如果使用批处理文件未安装服务,如何检入Windows

fle*_*eur 2 service batch-file

我正在尝试做一个批处理程序,需要检查服务是否已安装,然后再检查它是否正在运行/停止.

我想问一下,当操作系统是Windows XP时,是否有任何方法可以检查已卸载服务的ERRORLEVEL.

在我的代码段中:

ver | find /I "XP"
if %errorlevel%==0 goto ver_xp
goto ver_nonXP

:ver_xp
echo Windows XP
sc query myService > nul
echo %errorlevel%
if errorlevel ___I goto ServiceOk
if errorlevel ___ goto ServiceError
goto ServiceError

:ver_nonXP
echo Windows is not XP
sc query myService > nul
echo error1_percent %errorlevel%
if %errorlevel%==0 goto ServiceOk
if %errorlevel% NEQ '0' goto ServiceError
goto end

:ServiceError
echo Service is not installed
net helpmsg %errorlevel%
goto end

:ServiceError
rem do some operations here....
Run Code Online (Sandbox Code Playgroud)

我试着用

if errorlevel 1060 goto ServiceError
Run Code Online (Sandbox Code Playgroud)

似乎如果未安装该服务,则上述条件将始终为false.

我做了错误级别____因为我不知道应该是正确的条件.

wmz*_*wmz 5

sc query myService |find "myService" >nul 会做的