每天我都通过手动 ( start -> run ->services.msc
) 检查 Windows 服务。
但我想通过脚本自动化它。
如何使用 UNIX 脚本(.bat)检查特定窗口服务(例如 .tomcat)的状态(启动或停止)?
每天我都通过手动 ( start -> run ->services.msc
) 检查 Windows 服务。
但我想通过脚本自动化它。
如何使用 UNIX 脚本(.bat)检查特定窗口服务(例如 .tomcat)的状态(启动或停止)?
您可以使用sc query
或net start
来执行此操作。
例如。
@echo off
sc query "ServiceName" | findstr RUNNING
if %ERRORLEVEL% == 0 goto working
echo Not Running
:working
echo Running
goto end
:end
或者
@echo off
net start | findstr "ServiceName"
if %ERRORLEVEL% == 0 goto working
echo Not Running
goto end
:working
echo Running
:end