phesser
asked on
How do you Manipulate Services (Start/Stop) in Win2K on a Remote Machine- Using VB .NET and WMI??
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)....
Code:
Imports System.Diagnostics
Imports System.Drawing
Imports System.ComponentModel
Imports System.Windows.Forms
Imports System.Management
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.ObjectQu ery
Dim ms As System.Management.Manageme ntScope
'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.Manageme ntScope("\ \" + strComputerName + "\root\cimv2", co)
' Query remote computer across the connection
oq = New System.Management.ObjectQu ery(strQue ry)
query = New ManagementObjectSearcher(m s, oq)
queryCollection = query.Get()
For Each mo In queryCollection
' create child node for operating system
Dim errReturnCode
errReturnCode = mo.StopService()
Next
End Sub
::::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).
Thanks
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)....
Code:
Imports System.Diagnostics
Imports System.Drawing
Imports System.ComponentModel
Imports System.Windows.Forms
Imports System.Management
Private Sub 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.ObjectQu
Dim ms As System.Management.Manageme
'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.Manageme
' Query remote computer across the connection
oq = New System.Management.ObjectQu
query = New ManagementObjectSearcher(m
queryCollection = query.Get()
For Each mo In queryCollection
' create child node for operating system
Dim errReturnCode
errReturnCode = mo.StopService()
Next
End Sub
::::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).
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
That sparked what I needed.... I thought this class was only for C++/C#..but I just wasnt adding the reference to the .dll I needed.. ..
Appreciate it.