Check if a service is running with Win32_Service
I have a very quick question about Win3开发者_如何学Python2_Service
Is
String sState = service["State"].ToString();
if (! sState.Equals("Running"))
Sufficent to moniter if a service is not running? I want the if statement to return true in all cases where the service isn't running so it can send a warning message.
Windows service states are:
SERVICE_STOPPED
. Service is not running.SERVICE_START_PENDING
. Service is starting (but you can assume that it is not running. Hopefully the service will start soon)SERVICE_STOP_PENDING
. Service is stopping. (but you can assume that it is still running, except possibly the only thing service is doing is finishing in an orderly manner, disregarding any external request)SERVICE_RUNNING
. Service is running (and ready to meet external requests)SERVICE_CONTINUE_PENDING
. Similar toSTART_PENDING
. Hopefully the service will start soon.SERVICE_PAUSE_PENDING
. Service is going to be paused in the near future.SERVICE_PAUSED
. Service is paused
The only state that guarantees that the service is running is SERVICE_RUNNING
, but I would not display a warning if the service is in state START_PENDING
. At least, show different warnings depending on the state.
HTH.
精彩评论