stop process using WMI

0

I'm trying to stop a process on a remote machine using WMI

  try
      {

        ConnectionOptions connectionOptions = new ConnectionOptions();
        connectionOptions.Username = IFS_username;
        connectionOptions.Password = IFS_password;
        connectionOptions.Impersonation = ImpersonationLevel.Impersonate;

        ManagementScope scope = new ManagementScope("\\\\" + IFS_IP + "\\root\\CIMV2", connectionOptions);
        scope.Connect();
        ManagementPath path = new ManagementPath("Win32_Process");
        ManagementClass services;

        services = new ManagementClass(scope, path, null);
        foreach (ManagementObject service in services.GetInstances())
        {
            if (service.GetPropertyValue("Name").ToString().ToLower()=="notepad.exe")
            {

                service.InvokeMethod("Terminate", null);

            }


         }

       }

       catch (Exception ex)
          { textBox1.Text = ex.ToString(); }
       }

But I got the following exception

System.Runtime.InteropServices.COMException (0x800706BA):
The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)
 at System.Management.ThreadDispatch.Start()
 at System.Management.ManagementScope.Initialize()
 at System.Management.ManagementScope.Connect()

After some messing around the exception changed to

enter code here

I have checked couple of pages and it seems my method is correct, but I'm not able to find a solution for the exception.

c#
process
wmi
remote-access
asked on Stack Overflow May 20, 2015 by Jishnu U Nair • edited May 20, 2015 by Jishnu U Nair

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0