我有一个相当简单的任务要完成,但我对命令行脚本完全是个菜鸟。我搜索了一下,发现了一些与 Windows 机器上的服务交互的基本命令,但在检查服务是启动还是停止方面却一无所获。我希望有人可以帮助编写一个停止 3 项服务的脚本,检查以确保所有 3 项服务都已停止,并且一旦全部停止..重新启动它们。在启动其中任何一个备份之前,我需要确保所有 3 个都停止。我知道如何停止和启动服务,但剩下的就是我卡住的地方。
net Stop S1
net Stop S2
net Stop S3
//Check if all 3 are stopped
//If all 3 have been stopped successfully
net start s1
net start s2
net start s3
我想出了这个,但不认为语法是正确的......
net stop PriceIdxImport
net stop RawDataImportDB
net stop DBDailyTrxProcessService
set Pstate = sc query PriceIdxImport state
set Rstate = sc query RawDataImportDB state
set Dstate = sc query DBDailyTrxProcessService state
if Pstate == Inactive if Rstate == Inactive if Dstate == Inactive GOTO sub_StartServices
:sub_StartServices
net start PriceIdxImport
net start RawDataImportDB
net start DBDailyTrxProcessService
好吧,我把上面的脚本改成了一个while循环……它没有正确地循环吗?它检查了状态然后退出:(
echo on
net stop PriceIdxImport
net stop RawDataImportDB
net stop DBDailyTrxProcessService
ping -n 5 127.0.0.1 > nul
set Pstate = Sc query PriceIdxImport |find /i "STOPPED"
set Rstate = sc query RawDataImportDB |find /i "STOPPED"
set Dstate = sc query DBDailyTrxProcessService |find /i "STOPPED"
set Condition="false"
while Condition="false";do if Pstate neq "" ( if Rstate neq "" (if Dstate neq "" GOTO sub_StartServices));done
exit
:sub_StartServices
set Condition="true"
net start PriceIdxImport
net start RawDataImportDB
net start DBDailyTrxProcessService