ltlbearand3
asked on
vbscript to stop service on 64 bit machine
I have a script that runs great on 32 bit systems. However, when I run it on a 64 bit system, it fails to stop the service. It finds the service and adds it to the collection. However, the line:
Does not seem to work on 64 bit systems. Anyone see what I am missing?
I have tried elevating with UAC and running Wscript from c:\Windows\System32. Here is my script.
objService.Stopservice()
Does not seem to work on 64 bit systems. Anyone see what I am missing?
I have tried elevating with UAC and running Wscript from c:\Windows\System32. Here is my script.
strService = "MyLogService""
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\.\root\cimv2")
Set colListOfServices = objWMIService.ExecQuery _
("Select * from Win32_Service Where Name = '" & strService & "'")
' Check if the service has been found
If colListOfServices.Count > 0 Then
' Stop Service
For Each objService in colListOfServices
objService.Stopservice()
strStatus = objService.state
Next
' Verify Services have stopped
counter = 0
Do While Not strStatus = "Stopped"
Set colListOfServices = objWMIService.ExecQuery _
("Select * from Win32_Service Where Name = '" & strService & "'")
For Each objService in colListOfServices
strStatus = objService.state
wscript.sleep 1000
counter = counter + 1
If strStatus = "Stopped" Then
msgbox objService.Name & " has been stopped"
End IF
If counter > 5 then
msgbox "Failed to Stop " & objService.Name
strStatus = "Stopped"
End IF
Next
Loop ' Do While Not Stopped
End If ' Count > 0
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
One additional side note if someone else is looking at this. I ended up changing this line:
If the service name had spaces in it, this line failed. With the qoutes it will now run on those also.
objShell.Run "net stop " & objService.Name,0,False
toobjShell.Run "net stop """ & objService.Name & """",0,False
If the service name had spaces in it, this line failed. With the qoutes it will now run on those also.
ASKER