[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2011-05-10
12
Medium Priority
?
1,684 Views
Last Modified: 2012-05-11
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

0
Comment
Question by:NCSA SCADA
  • 6
  • 3
  • 2
  • +1
12 Comments
 
LVL 31

Expert Comment

by:merowinger
ID: 35731336
try:
colProcesses = New ManagementObjectSearcher("Select * FROM Win32_Process WHERE Name ='spoolsv.exe'")
0
 

Author Comment

by:NCSA SCADA
ID: 35731471
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
 
LVL 31

Expert Comment

by:merowinger
ID: 35731496
so the script just looks like? Where does it fail?
Firewall on the remote Client off? Does it work Local?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:NCSA SCADA
ID: 35731566
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
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 35731604
Comment out the InvokeMethod line to see if that is the source of the error or the retrieval of processes.
0
 

Author Comment

by:NCSA SCADA
ID: 35731631
Yep.... it is the source
0
 
LVL 31

Expert Comment

by:merowinger
ID: 35731633
0
 

Author Comment

by:NCSA SCADA
ID: 35732249
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
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 35732338
>.. 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
 

Author Comment

by:NCSA SCADA
ID: 35732562
It is an admin on the remote system
0
 
LVL 15

Accepted Solution

by:
Russell_Venable earned 1000 total points
ID: 35736768
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
 

Author Closing Comment

by:NCSA SCADA
ID: 35863779
thanks
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Suggested Courses

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question