Starting and stopping NT services 
Author Message
 Starting and stopping NT services

Hi,

I am interested in a sample script to check to see if a service is
running, stop the service and restart it after a condition is satisfied.

Any help appreciated.

Thanks
Rick



Fri, 24 Jan 2003 03:00:00 GMT  
 Starting and stopping NT services
Both ADSI and WMI support this.  There are examples in the respective FAQs on Clarence's site...

Win32 Scripting [Clarence Washington]
http://cwashington.netreach.net
http://cwashington.netreach.net/script_repository/repository.asp
http://cwashington.netreach.net/script_repository/query.asp
http://cwashington.netreach.net/main_site/downloads
http://cwashington.netreach.net/script_repository/faqs.asp?topic=wmifaq
http://cwashington.netreach.net/script_repository/faqs.asp?topic=adsifaq

--
Michael Harris
MVP Scripting


Hi,

I am interested in a sample script to check to see if a service is
running, stop the service and restart it after a condition is satisfied.

Any help appreciated.

Thanks
Rick



Fri, 24 Jan 2003 03:00:00 GMT  
 Starting and stopping NT services
Take this example to check Spooler Service, you need ADSI installed

SET service=GetObject("WinNT://YOURDOMAIN/YourComputer/Spooler,service")

    select case Service.status
       case 1
          ServiceStatus="Stopped"

       case 2
          ServiceStatus="Start Pending"

       case 3
          ServiceStatus="Stop Pending"

       case 4
          ServiceStatus="Running"

       case 5
          ServiceStatus="Continue_Pending"

       case 6
          ServiceStatus="Pause Pending"

       case 7
          ServiceStatus="Paused"

       case 8
          ServiceStatus="Error"

     end Select
     wscript.echo service.name & vbtab & service.status _
                  & vbtab & ServiceStatus

'Starting Service if stopped
'
if Service.status = 1 then

    service.start  '
    wscript.echo "The " & service.name & " service has been started"
  else
    if service.status = 4 then
       wscript.echo "The " & service.name & " service is already
started"
    else
       wscript.echo "The " & service.name & " service could not be
started"
    end if
end if

Other "service" methods that you could use related to stop/start a
service.
In the previous example you could use
service.stop
service.pause
service.continue

regards



Quote:
> Hi,

> I am interested in a sample script to check to see if a service is
> running, stop the service and restart it after a condition is
satisfied.

> Any help appreciated.

> Thanks
> Rick


Sent via Deja.com http://www.deja.com/
Before you buy.


Sat, 25 Jan 2003 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

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

2. Starting and Stopping NT Services from WSH/VBS

3. How to start/stop a NT service

4. Stop and Starting Services on NT

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

6. How to start/stop a NT service...

7. Script To Stop/Start NT Service

8. Stopping and Starting NT Services

9. Stopping and Starting NT Services

10. Stop/Start NT Services

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

12. Starting/Stopping NT Services

 

 
Powered by phpBB® Forum Software