我想检查服务是否正在运行。如果它是我希望它被停止。我确实有很多服务,所以我希望它可以在数组中运行或者某些服务。
据我所知:
for /F "tokens=3 delims=: " %%H in ('sc query "MyServiceName" ^| findstr " STATE"') do (
if /I "%%H" NEQ "RUNNING" (
REM Put your code you want to execute here
REM For example, the following line
net stop"MyServiceName"
)
然后我有例如service1,service2,service3和service4
如果不需要将此for循环写入四次,这怎么可以加入呢?
答案 0 :(得分:0)
for %%S in ("service1" "service2" "service3") do (
for /F "tokens=3 delims=: " %%H in ('sc query "%%~S" ^| findstr " STATE"') do (
if /I "%%H" NEQ "RUNNING" (
REM Put your code you want to execute here
REM For example, the following line
net stop"%%~S"
)
)