罗斯的代码我张贴也可以知道有多少服务正在运行...
想象一下,你要知道有多少服务,如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