Search code examples
c#wmi

How to kill process on remote computer with wmi


I'm trying to kill a process on a remote computer, but it's not working, and i'm not getting any errors. I'm using this code:

            ManagementScope scope = new ManagementScope("\\\\" + txtMaquina.Text + "\\root\\cimv2");
            scope.Connect();
            ObjectQuery query = new ObjectQuery("select * from Win32_process where name = '" + lstProcessos.SelectedItem.ToString() + "'");
            ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query);
            ManagementObjectCollection objectCollection = searcher.Get();
            foreach (ManagementObject managementObject in objectCollection)
                managementObject.InvokeMethod("Terminate", null);

The computer name is txtMaquina.Text and the process name i'm getting from a selected item on a ListView

Someone have any idea what's wrong here?


Solution

  • I solved my problem using this solution on Code Project: http://www.codeproject.com/Articles/18146/How-To-Almost-Everything-In-WMI-via-C-Part-Proce