Avatar of V Thrusher
V Thrusher

asked on 

Vb script to restart the services

I have wrote the script to stop application services. first it will stop SIA services and wait for 10 seconds & after that second services is stopped. Now i want to include a condition to check whether first SIA services is stopped or not and if stopped then only it can proceed to stopping the second services...can someone help me pls to modify this code

Option Explicit
Dim objWMIService, objService
Dim stpServicesia,stpServicetom,strComputer,waitTime
stpServicesia="SIA"
stpServicetom="BOE120Tomcat7"
strComputer = "samplesystemtname"
waitTime=10000
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
For Each objService In objWMIService.ExecQuery("Select * from Win32_Service Where Name = '"_
&stpServicesia&"'")
objService.StopService()
Next
WScript.Sleep 10000
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
For Each objService In objWMIService.ExecQuery("Select * from Win32_Service Where Name = '"_
&stpServicetom&"'")
objService.StopService()
Next
WScript.Quit
VB Script

Avatar of undefined
Last Comment
V Thrusher

8/22/2022 - Mon