From the system administration Script Guide Script Repository (http://www.microsoft.com/downloads/release.asp?ReleaseID=38942)

 

Stop a Service and Its Dependents

Description
Stops the NetDDE service and all its dependent services.

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colServiceList = objWMIService.ExecQuery("Associators of " _
   & "{Win32_Service.Name='NetDDE'} Where " _
        & "AssocClass=Win32_DependentService " & "Role=Antecedent" )
For each objService in colServiceList
    objService.StopService()
Next
Wscript.Sleep 20000
Set colServiceList = objWMIService.ExecQuery _
        ("Select * from Win32_Service where Name='NetDDE'")
For each objService in colServiceList
    errReturn = objService.StopService()
Next

 

 

 

Start a Service and Its Dependents

Description
Starts the NetDDE service and all its dependent services.

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colServiceList = objWMIService.ExecQuery _
    ("Select * from Win32_Service where Name='NetDDE'")
For each objService in colServiceList
    errReturn = objService.StartService()
Next
Wscript.Sleep 20000
Set colServiceList = objWMIService.ExecQuery("Associators of " _
   & "{Win32_Service.Name='NetDDE'} Where " _
        & "AssocClass=Win32_DependentService " & "Role=Dependent" )
For each objService in colServiceList
    objService.StartService()
Next

 

 

You should be able to adjust this for your specific service and make 2 scripts that you could put into your scheduled tasks, 1 for shut down, the other for start up.

 

Rick J. Jones

 

 

-----Original Message-----
From: Kevin Felker [mailto:[EMAIL PROTECTED]]
Sent: Friday, October 11, 2002 9:47 AM
To: [EMAIL PROTECTED]
Subject: [ActiveDir] OT: How to schedule a service to stop and restart?

 

All,

 

I'm trying to do a system backup of my server, but not all of it is

backing up since certain services are running (such as SQL SERVER).

 

If I have my backup scheduled for 3:00AM, I would like to stop the SQL

SERVER Service at 2:50AM, and restart it at 4:00AM.

 

What is the best way to do this?

 

Thanks

 

Kevin

List info   : http://www.activedir.org/mail_list.htm

List FAQ    : http://www.activedir.org/list_faq.htm

List archive: http://www.mail-archive.com/activedir%40mail.activedir.org/

Reply via email to