
stop/start a service in VBS
Quote:
> I have a vbscript that I run within SQL Server Agent. I need to chagne the
> script to stop and later restart a service on the local machine. Assume the
> service is MyService. Can someone tell me the correct syntax to stop and
> start the service.
Hi
You can use WMI as well as ADSI for this, but the simplest way is to just shell
out and run Net Stop (alt. Start).
Set oShell=WScript.CreateObject("WScript.Shell")
sServiceName = "MyService"
' Stop service:
oShell.Run "Net Stop " & Chr(34) & sServiceName & Chr(34), 0, True
' Start service:
oShell.Run "Net Start " & Chr(34) & sServiceName & Chr(34), 0, True
Chr(34) (a.k.a. ") is added just in case the service name has one or more
space(s) in it.
--
torgeir