PDA

View Full Version : Code to check status of specified services on remote machine


ShiftySid
09-19-2006, 11:38 AM
Hi guys, I am writing an application that will have a list of servers in one checklist box and a list of Windows services in another.

I want to be able to check a server (or servers) and check some Windows services, then click a button to return the status of those serivces in a text box.

I can get all of this to work, with the exception of the following:

1) I can only check services on the local machine, how can I check services on a remote machine?

2) How can I convert the checked items of a checklist box to individual string variables?

Here's my code, thus far (help is mainly needed with point 1, as I have ways of overcoming point 2- thanks in advance):

Function IsServiceRunning(ByVal sServiceName, ByVal sMachineName)

Dim objMachine, objInst, objSet
objSet = GetObject("winmgmts:").ExecQuery("SELECT * FROM Win32_Service")

For Each objInst In objSet
If (UCase(sServiceName) = UCase(objInst.Name)) And (UCase(objInst.State) = UCase("Running")) Then
txtResults.Text &= (sServiceName & " - running") & vbCrLf
End If

If (UCase(sServiceName) = UCase(objInst.Name)) And (UCase(objInst.State) = UCase("Stopped")) Then
txtResults.Text &= (sServiceName & " - stopped") & vbCrLf
End If

Next
End FunctionCOLOR=Blue