
How to start/stop services with vbscript?
Quote:
> How can I start or stop a windows service from a vbscript?
Ritchie showed you how to use net.exe from a vbscript, I can show you how to do
it with ADSI as well as WMI:
Using ADSI:
' Stop the messenger service:
Const ADS_SERVICE_RUNNING = 4
sServer = "." ' "." for local machine
Set oComputer = GetObject("WinNT://" & sServer & ",computer")
Set oService = oComputer.GetObject("Service", "Messenger")
If oService.Status = ADS_SERVICE_RUNNING Then
oService.Stop
End If
IADsService
http://msdn.microsoft.com/library/en-us/netdir/adsi/iadsservice.asp
IADsServiceOperations
http://msdn.microsoft.com/library/en-us/netdir/adsi/iadsserviceoperat...
Using WMI:
sServer = "." '"." for local machine
Set oWMI = GetObject("winmgmts://" & sServer)
' using the fax service as an example
sServiceName = "Fax"
sWQL = "Select state from Win32_Service " _
& "Where displayname='" & sServiceName & "'"
Set oResults = oWMI.ExecQuery(sWQL)
For Each oService In oResults
If LCase(oService.State) = LCase("Running") Then
oService.StopService
End If
Next
Win32_Service
http://msdn.microsoft.com/library/en-us/wmisdk/wmi/win32_service.asp
--
torgeir
Microsoft MVP Scripting and WMI
Porsgrunn Norway