Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: [VBScript] restart a service  (Read 8439 times)

0 Members and 1 Guest are viewing this topic.

mangolzy

    Topic Starter


    Rookie

    • Experience: Beginner
    • OS: Windows 7
    [VBScript] restart a service
    « on: June 27, 2014, 06:58:55 AM »
    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!!

    mangolzy

      Topic Starter


      Rookie

      • Experience: Beginner
      • OS: Windows 7
      Re: [VBScript] restart a service
      « Reply #1 on: June 27, 2014, 09:01:40 AM »
      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!!!