1.

Solve : [VBScript] restart a service?

Answer»

with this, i can get the result ACCORDING to the state of WebClient, that means we can find the Service and get its state correctly

Code: [Select]service = "WebClient"
Set wmi = GetObject("winmgmts:\\.\root\cimv2")
QRY = "SELECT * FROM Win32_Service WHERE Name='" & service & "'"
For Each s In wmi.ExecQuery(qry)
If s.State = "Stopped" Then WScript.Echo "stop"
If s.State = "Running" Then WScript.Echo "start"
Next

but why does it not function to do the stop / start?? no return value, nothing>>>>>>

Code: [Select]service = "WebClient"
Set wmi = GetObject("winmgmts:\\.\root\cimv2")
qry = "SELECT * FROM Win32_Service WHERE Name='" & service & "'"
For Each s In wmi.ExecQuery(qry)
If s.State = "Stopped" Then s.StartService
If s.State = "Running" Then s.StopService
Next

I appreciate your reply , thank you!!finally, i realize that's because i didn't execute it as the administator.

i can do it simply with a CLICK on the right.

BUT, if i want this .exe file to be executed in hundreds of machine in DISTANCE, it's really the very object that i want to avoid this kind of click, how can i make it executed as the administrator everytime? it's not possible by programming??

HELP!!!



Discussion

No Comment Found