Windows command to get service status?

后端 未结 12 897
渐次进展
渐次进展 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:24

    my intention was to create a script which switches services ON and OFF (in 1 script)

    net start NameOfSercive 2>nul
    if errorlevel 2 goto AlreadyRunning
    if errorlevel 1 goto Error
    

    ...

    Helped a lot!! TYVM z666

    but when e.g. service is disabled(also errorlevel =2?)it goes to "AlreadyRuning"and never comes to

    if errorlevel 1 goto Error  ?!!
    

    i wanted an output for that case ...

     :AlreadyRunning
     net stop NameOfSercive
     if errorlevel 1 goto Error
    
    
     :Error
     Echo ERROR!!1!
     Pause
    

    my 2 Cents, hope this helps

提交回复
热议问题