Справочник по C#

    Исходники по языку программирования CSharp

    WMI remove service(Удаление службы через WMI): Справочник по C#

    /
    /
    /
    44 Views


    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("Возникли проблемы при удалении службы!");
    }
    }
    

    WMI remove service(Удаление службы через WMI): Справочник по C#

    0.00 (0%) 0 votes

    moyadcode13
    • Facebook
    • Twitter
    • Google+
    • Linkedin
    • Pinterest
    moyadcode10
    moyadcode11
    moyadcode9