stop/start a service in VBS 
Author Message
 stop/start a service in VBS

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.

Thx,
James



Thu, 16 Sep 2004 16:06:07 GMT  
 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



Thu, 16 Sep 2004 13:19:54 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Starting and stopping Services from ASP or VBS

2. Starting and Stopping NT Services from WSH/VBS

3. Starting, stopping and pauseing a service.

4. Problems with stopping/starting service

5. How to start/stop services with vbscript?

6. START/STOP/ displayed Services running on PC thu an ASP page

7. How to start/stop a NT service

8. start and stop services

9. login script to start/stop service

10. Stop and Starting Services on NT

11. Starting and Stopping NT Services with ADSI,wsh, and VBScript

12. Start/Stop a NT Service using wsh/adsi

 

 
Powered by phpBB® Forum Software