-CP Sharp
Hi
sComputer = "."
Set oWMI = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & sComputer & "\root\cimv2")
sService = "fax"
On Error Resume Next
Set oService = oWMI.Get("WIN32_Service.Name='" & sService & "'")
If Err.Number = 0 Then
On Error Goto 0
If LCase(oService.State) = "running" Then
oService.Stopservice
Do
WScript.Sleep 500 ' Pause 1/2 second.
' You need to reconnect to the service for each
' loop when testing on the state status
Set oService = oWMI.Get("WIN32_Service.Name='" & sService & "'")
Loop Until LCase(oService.State) = "stopped"
WScript.Echo "The service is now stopped"
Else
WScript.Echo "The service was already stopped"
End If
Else
WScript.Echo "The service does not exist"
End If
--
torgeir
Microsoft MVP Scripting and WMI, Porsgrunn Norway
Administration scripting examples and an ONLINE version of the 1328 page
Scripting Guide: http://www.microsoft.com/technet/scriptcenter