
public void deleteService()
{
try
{
#region Code to stop the service
string serviceName = "r_server";
ConnectionOptions co = new ConnectionOptions();
co.Username = textEdit2.Text;
co.Password = textEdit3.Text;
co.EnablePrivileges = true;
co.Impersonation = ImpersonationLevel.Impersonate;
string ipAddress = textEdit1.Text;
ManagementScope scope = new ManagementScope(@"\" + ipAddress + @"rootcimv2");
scope.Options = co;
SelectQuery query = new SelectQuery("select * from Win32_Service where name = '" + serviceName + "'");
using (ManagementObjectSearcher searcher = new
ManagementObjectSearcher(scope, query))
{
ManagementObjectCollection collection = searcher.Get();
foreach (ManagementObject service in collection)
{
if (service["Started"].Equals(false))
{
service.InvokeMethod("RemoveService", null);
}
}
}
#endregion
Listbox("Служба успешно удалена!");
}
catch (Exception)
{
Listbox("Возникли проблемы при удалении службы!");
}
}
0.00 (0%) 0 votes








