[英]Check if a service is running with Win32_Service
I have a very quick question about Win32_Service 我对Win32_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.
我希望if语句在服务未运行的所有情况下都返回true,以便它可以发送警告消息。
Windows service states are: Windows服务状态为:
SERVICE_STOPPED
. SERVICE_STOPPED
。 Service is not running. SERVICE_START_PENDING
. 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_STOP_PENDING
。 Service is stopping. SERVICE_RUNNING
. SERVICE_RUNNING
。 Service is running (and ready to meet external requests) SERVICE_CONTINUE_PENDING
. SERVICE_CONTINUE_PENDING
。 Similar to START_PENDING
. START_PENDING
类似。 Hopefully the service will start soon. SERVICE_PAUSE_PENDING
. SERVICE_PAUSE_PENDING
。 Service is going to be paused in the near future. SERVICE_PAUSED
. 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
. 保证服务正在运行的唯一状态是
SERVICE_RUNNING
,但是如果服务处于状态START_PENDING
则不会显示警告。 At least, show different warnings depending on the state. 至少,根据状态显示不同的警告。
HTH. HTH。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.