Service 如果未使用批处理文件安装服务,如何在Windows中签入

Service 如果未使用批处理文件安装服务,如何在Windows中签入,service,batch-file,Service,Batch File,我正在尝试执行一个批处理程序,在检查服务是否正在运行/停止之前,需要检查服务是否已安装 我只是想问一下,当操作系统是Windows XP时,是否有任何方法可以检查已卸载服务的错误级别 在我的代码片段中: 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 errorleve

我正在尝试执行一个批处理程序,在检查服务是否正在运行/停止之前,需要检查服务是否已安装

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

在我的代码片段中:

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....
我试着用

if errorlevel 1060 goto ServiceError
如果没有安装服务,上述条件似乎总是错误的


我之所以做了errorlevel,是因为我不知道应该是正确的条件。

根据这个答案,可以使用您描述的方法批量执行

或者,您可以使用powershell进行查询:

$serv_status = get-service "myService"
if($serv_status -ne $null) 
{ 
    // do some operations here
}

sc query myService | find“myService”>nul
会成功的

谢谢您的回答。我只喜欢批处理文件,因为这是我被告知要使用的文件。我已经看到了这个链接,但是我发现在我的“if”条件下捕捉错误本身有困难。返回的错误为“.service not installed…”与提供的链接不同。我不知道是否可以为返回的特定字符串(使用net)进行管道连接。我还没有找到任何命令。