我得到了
[SC] StartService失败1056该服务的实例已在运行。
对于w3svc
,当我尝试使用以下方式在批处理文件中启动服务时:
sc \\%server% query w3svc | find "STATE" | find "RUNNING"
sc \\%server% start w3svc
这仅在我进行更改后运行构建时发生。
出于某种原因,它表示服务正在运行,而实际上却没有。
答案 0 :(得分:1)
尝试:
sc \\%server% query w3svc | findstr "STATE RUNNING" >nul 2>&1 || (
sc \\%server% start w3svc
)
答案 1 :(得分:1)
这些是状态。您仅在检查是否正在运行。除了一个以外,其他所有人都将返回“跑步”。
https://msdn.microsoft.com/en-us/library/cc245911.aspx
dwCurrentState
The current state of the service. This member can be one of the following values. Value Meaning
SERVICE_CONTINUE_PENDING The service continue is pending.
SERVICE_PAUSE_PENDING The service pause is pending.
SERVICE_PAUSED The service is paused.
SERVICE_RUNNING The service is running.
SERVICE_START_PENDING The service is starting.
SERVICE_STOP_PENDING The service is stopping.
SERVICE_STOPPED The service is not running.