Windows command to get service status?

后端 未结 12 781
渐次进展
渐次进展 2021-02-01 04:48

I need to know the status of a service at the end of my batch script which restarts services using \"net stop thingie\" and \"net start thingie\".

In my most favorite id

12条回答
  •  悲哀的现实
    2021-02-01 05:13

    Have you tried sc.exe?

    C:\> for /f "tokens=2*" %a in ('sc query audiosrv ^| findstr STATE') do echo %b
    4  RUNNING
    
    C:\> for /f "tokens=2*" %a in ('sc query sharedaccess ^| findstr STATE') do echo %b
    1  STOPPED
    

    Note that inside a batch file you'd double each percent sign.

提交回复
热议问题