How do you Manipulate Services (Start/Stop) in Win2K on a Remote Machine- Using VB .NET and WMI??
Posted on 2003-11-26
Ok, here is my problem...
I have been going back and forth trying to use WMI, and inherent VB .NET code to manipulate processes/services and so far have not been able to get it to work...
I can get it to work on my local machine, but when I try it on a remote machine, I get an error ' this feature is not supported' ... now I do understand why as its a powerful tool, but we utilize 100's of servers, and over 400,000 client machines, and having this function would be very helpful...
Its easy in script form (WMI/VB), but in the console it seems to have some safeguards in place, or I am just missing one key feature... anyway here is the code.... any help is appreciated. (Note, I only use WMI and VB.net , no C++/C# please)....
Private Sub Service_Stop_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Service_Stop_Button.Click
Const CRLF As String = Chr(13) & Chr(10)
Dim query As ManagementObjectSearcher
Dim queryCollection As ManagementObjectCollection
Dim co As ConnectionOptions
Dim oq As System.Management.ObjectQuery
Dim ms As System.Management.ManagementScope
'Dim mo As ManagementObject
Dim mo As ManagementObject
Dim strComputerName, strQuery As String
strComputerName = LogView_ComboBox.Text
strQuery = "SELECT * FROM Win32_Service Where Name = 'RADEXECD'"
' Connect to the remote computer
co = New ConnectionOptions()
' Point to machine
ms = New System.Management.ManagementScope("\\" + strComputerName + "\root\cimv2", co)
' Query remote computer across the connection
oq = New System.Management.ObjectQuery(strQuery)
query = New ManagementObjectSearcher(ms, oq)
queryCollection = query.Get()
For Each mo In queryCollection
' create child node for operating system
errReturnCode = mo.StopService()
::::End Code :::
Note: In this code I am trying to query the RADEXECD service... I want to be able to stop/start, etc... but from what I see I am getting an error at the mo.StopService() (Stating that this isnt a function of the System.Management class in Win32_Service).... but its the same thing thats used in WMI.. so not sure what I am missing... anyone have any ideas? Is there something else I need to do to enable remote service manipulation?? or another route I can go... (Note: I do have admin rights to all the remote machines).