Link to home
Start Free TrialLog in
Avatar of derek7467
derek7467

asked on

vb.net and WMI - remote process killing

Attempting to kill a remote process using vb.net and wmi.  I can query the processes fine and is a specify a process ID to kill, it works fine, but when i try and set the process id as variable it fails.  Assuming it fails because im not calling the selecteditem properly:

Dim RC As String = TextBox1.Text
        Dim taskID As String = listview2.selecteditems (doesnt work), (when i replace with "4784", it works)

        Dim theScope As New ManagementScope("\\" & RC & "\root\cimv2")
        Dim objectQuery As New ObjectQuery(String.Concat("SELECT * FROM Win32_Process WHERE ProcessID='", taskID, "'"))
        For Each managementObject As ManagementObject In (New ManagementObjectSearcher(theScope, objectQuery)).[Get]()
            managementObject.InvokeMethod("Terminate", Nothing)
        Next
    End Sub

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of derek7467
derek7467

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial