Link to home
Start Free TrialLog in
Avatar of V Thrusher
V Thrusher

asked on

vb script to start the services is not working

trying to start the vb script but unfortunately its not working, need your help pls
Option Explicit
Dim objWMIService, objService
Dim strService,strComputer,waitTime
strService="Audiosrv"
strComputer = "VishnuAdithya"
waitTime=10000
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
For Each objService In objWMIService.ExecQuery("Select * from Win32_Service Where Name = '"_
&strService&"'")
objService.StartService() 
 
Next
 
WScript.Quit

Open in new window

Avatar of Anastasia D. Gavanas
Anastasia D. Gavanas
Flag of Greece image

try
Set colRunningServices = objWMIService.ExecQuery _
        ("Select * from Win32_Service where Name = '"& strService & "'")
    For Each objService in colRunningServices
also check similar case here
https://blogs.technet.microsoft.com/kevinholman/2016/01/24/writing-a-service-recovery-script-cluster-service-example/
like:
Sub ServiceStart(strService)
    Dim objWMIService, colRunningServices, objService, colServiceList
    Set objWMIService = GetObject("winmgmts:" _
        & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
    Set colServiceList = objWMIService.ExecQuery _
        ("Select * from Win32_Service where Name='"& strService & "'")
    For Each objService in colServiceList
        errReturn = objService.StartService()
    Next
End Sub
ASKER CERTIFIED SOLUTION
Avatar of Kimputer
Kimputer

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of V Thrusher
V Thrusher

ASKER

Kim you are genius! Thanks a lot !!!