羅斯的代碼我張貼也可以知道有多少服務正在運行...
想象一下,你要知道有多少服務,如Oracle *,那麼你把甲骨文,而不是NameOfSercive ......,你會得到在變量%了countLines%運行Oracle這樣的服務的數量*如果你想如果只有4做一些事情,你可以做這樣的事情:
IF 4點==%了countLines%GOTO FourServicesAreRunning
這是更強大的功能...並且你的代碼不會讓你知道是否需要服務正在運行......如果有的話她srecive開始用相同的名字......想象: -ServiceOne -ServiceOnePersonal
如果搜索ServiceOne,但它只運行ServiceOnePersonal你的代碼會告訴ServiceOne運行...
我的代碼可以伊斯利改變,因爲它逐行讀取它也可以做任何你想做的每個服務的文件的所有線和讀取線......看到這一點:
@ECHO OFF
REM Put here any code to be run before check for Services
SET TemporalFile=TemporalFile.TXT
NET START > %TemporalFile%
SET CountLines=0
FOR /F "delims=" %%X IN (%TemporalFile%) DO SET /A CountLines=1+CountLines
SETLOCAL EnableDelayedExpansion
SET CountLine=0
FOR /F "delims=" %%X IN (%TemporalFile%) DO @(
SET /A CountLine=1+CountLine
REM Do whatever you want to each line here, remember first and last are special not service names
IF 1==!CountLine! (
REM Do whatever you want with special first line, not a service.
) ELSE IF %CountLines%==!CountLine! (
REM Do whatever you want with special last line, not a service.
) ELSE (
REM Do whatever you want with rest lines, for each service.
REM For example echo its position number and name:
echo !CountLine! - %%X
REM Or filter by exact name (do not forget to not remove the three spaces at begining):
IF " NameOfService"=="%%X" (
REM Do whatever you want with Service filtered.
)
)
REM Do whatever more you want to all lines here, remember two first are special as last one
)
DEL -P %TemporalFile% 2>nul
SET TemporalFile=
REM Put here any code to be run after check for Services
當然它只能運行列表中的服務,我做不知道任何方式網可以列出不運行服務...
希望這有助於!
選擇,因爲不需要安裝。感謝你們! – 2009-04-29 12:36:36