none
Batch command to find service running or not RRS feed

  • Question

  • HI All,

           I have task to write batch script and find particular service  is existed or not.If service is existed then I would like to know is it running or not.Can any one help me how can I do this


    Samar

    Friday, April 4, 2014 10:10 AM

Answers

All replies

  • With the get-service command you can do this.

    Using get-service "w3svc" will show you the status of the service w3svc (World Wide Web Publishing Service)

    If you put the info in a variable, you can query against that. Thus for instance:

    $ServiceInfo = Get-Service "w3svc"

    You can check if the service is running by checking its status:

    $ServiceInfo.Status

    Friday, April 4, 2014 10:38 AM
  • Use sc.exe, e.g. sc.exe query w32time
    Friday, April 4, 2014 10:46 AM
  • Something like

    sc query ALG | findstr /i "STATE"

    Result:

    "STATE              : 1  STOPPED"

    Friday, April 4, 2014 11:05 AM