我有一個相當簡單的任務,但在命令行腳本中總是noob。我搜索了一下,發現了一些基本命令與Windows機器上的服務進行交互,但沒有檢查服務是啓動還是停止。我希望有人可以幫助一個腳本,將停止3個服務,檢查以確保所有3個都停止,並且一旦所有的都停止了。再次啓動它們。我需要確保在啓動任何3個備份之前,所有3個都已停止。我知道如何停止和開始服務,但剩下的就是我卡住的地方。如何停止Windows服務,檢查它是否已停止,並使用命令行重新啓動它?
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
好吧,我把上面的腳本,並將其改變成而loop..it犯規正確地做循環?它檢查狀態,然後退出:(
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
批量變量賦值必須這樣做:'設置VAR = foo的bar'(不帶空格周圍的'= ') – 2013-02-27 21:21:47
好吧我把3個語句改成了沒有空格,所以它適合var = xxx格式 – user1732364 2013-02-28 14:45:16