Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBscript to restart multiple processes

Status
Not open for further replies.

limester

Technical User
Dec 29, 2004
69
CA
Hi,

I have a script that will successfully restart a single process but I need to restart 3 and strService3 is the parent so this one has to be stopped last.

Option Explicit
Dim objWMIService, objItem, objService
Dim colListOfServices, strComputer, strService1, strService2, strService3, intSleep
strComputer = "."
intSleep = 15000
WScript.Echo " Click OK, then wait " & intSleep & " milliseconds"

'On Error Resume Next
' NB strService is case sensitive.
strService1 = " 'Child1' "
strService2 = " 'Child2' "
strService3 = " 'Parent' "
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\cimv2")
Set colListOfServices = objWMIService.ExecQuery _
("Select * from Win32_Service Where Name ="_
& strService1 & " ")
For Each objService in colListOfServices
objService.StopService()
WSCript.Sleep intSleep
objService.StartService()
Next
WScript.Echo "The "& strService1 & " service has Started"
WScript.Quit

Any help is greatly appreciated!

Thanks!
 
you would be better off returning all the services running in your WMI, then loop through this collection comparing the name of each service against another collection (one you create in memory, i.e. a dictionary or array) of services which need to be acted up. you could have your collection in memory in the order in which you want them to be stopped? or you could have a collection of objects ( a class you define yourself) which have a .Action and .Order property, etc
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top