VB.Net - trying to kill a remote process with wmi

I am trining to kill a remote process using WMI and I get an invalid query error.  I'm not sure what I'm doing wrong... any help would be great... thanks
Dim Computername As String = ComboBox1.SelectedValue
        Dim colProcesses As ManagementObjectSearcher
        Dim colObserver As New ManagementOperationObserver
        Dim refProcess As ManagementObject
        Dim sProcess As String = "spoolsv"
        Dim options As ConnectionOptions
        options = New ConnectionOptions()
        options.Username = "User"
        options.Password = "Passwords"

        colProcesses = New ManagementObjectSearcher("Select * FROM Win32_Process WHERE Name =	spoolsv.exe")
        colProcesses.Scope = New ManagementScope("\\" & Computername & "\root\cimv2", options)
        Try
            colProcesses.Scope.Connect()

            If colProcesses.Get.Count = 0 Then

            Else
                Try
                    For Each refProcess In colProcesses.Get

                        refProcess.InvokeMethod(colObserver, "Terminate", Nothing)

                    Next
                Catch ex As Exception
                    MsgBox(ex.Message)
                End Try
               

            End If
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try

Open in new window

NCSA SCADAAsked:
Who is Participating?
 
Russell_VenableConnect With a Mentor Commented:
Error 0x800706ba is normally caused by the RPC services being disabled on the other end. Check to make RpcSs.exe is running in taskmanager and also check the status of the service by navigating to services.msc in your run box, and search for "Remote Procedure Call" and make sure the service is running. If the service is disabled or stopped set it to automatic and reboot. If your still getting the error after a reboot run DCOMCNFG.exe and Follow these instructions.

For a local computer, right-click My Computer, and then click Properties

For a remote computer, right-click the Computers folder, click New, click Computer, type the computer name, right-click that computer name, and then click Properties,

Click the Default Properties tab.
Check to make sure "Enable COM Internet Services on this Computer" check box is checked, hit apply, Ok, then reboot and try again.
0
 
merowingerCommented:
try:
colProcesses = New ManagementObjectSearcher("Select * FROM Win32_Process WHERE Name ='spoolsv.exe'")
0
 
NCSA SCADAAuthor Commented:
That looks to have cleaned up the query (I feel silly for that one) but now I get the following
rpc server is unavailable - exception from hrsult:0x800706ba

I am able to query the status of the proceses and services but not stop
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
merowingerCommented:
so the script just looks like? Where does it fail?
Firewall on the remote Client off? Does it work Local?
0
 
NCSA SCADAAuthor Commented:
there is no firewall on the remote system...
I receive the an error message from this catch


Try
                    For Each refProcess In colProcesses.Get

                        refProcess.InvokeMethod(colObserver, "Terminate", Nothing)

                    Next
                Catch ex As Exception
                    MsgBox("1" & ex.Message)
                End Try

Open in new window

0
 
CodeCruiserCommented:
Comment out the InvokeMethod line to see if that is the source of the error or the retrieval of processes.
0
 
NCSA SCADAAuthor Commented:
Yep.... it is the source
0
 
NCSA SCADAAuthor Commented:
did you send the link becuase of the domain reference... the remote server is not part of a domain.... the account I am using is an admin, and it looks like I am making it past the connection .. the query looks to be working as if cloprocesses.get.count was 0 it would never make to the invokemethod...
If there is somthing else you wanted me to look at please let me know with more detail...

Thanks for the info

any ideas experts
0
 
CodeCruiserCommented:
>.. the account I am using is an admin
Admin of the PC running this program or admin of the pc where you are killing the process?
0
 
NCSA SCADAAuthor Commented:
It is an admin on the remote system
0
 
NCSA SCADAAuthor Commented:
thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.