开发者

How to check the existence of a Windows service in a batch file

How can I check the existence of a Windows service in a b开发者_JS百科atch file?

The user is inputting a service name, and I want to check that the service does exist before continuing with my script.


Try this:

>NET START | FIND "Workstation"

where "Workstation" is the name of the service


@echo off

color 1F



SET KEYS=HKLM\SYSTEM\CurrentControlSet\services\ACPI

for /f "tokens=3" %%i in ('REG QUERY "%KEYS%" ^| find "Start"') do set START=%%i

IF "%START%" == "%START%" ECHO %START% | find /I "%START%" && IF "%START%" NEQ "0x3" REG ADD %KEYS% /v "Start" /t REG_DWORD /d 3 /f >> %COMPUTERNAME%_MODIFIER.TXT

IF ERRORLEVEL 1 ECHO %KEYS% >> %COMPUTERNAME%_SERVICE_MISSING.TXT

OR

@echo off
color 1F


@sc query >%COMPUTERNAME%_START.TXT

ECHO REPORT MISSING INSTALL SERVICES >%COMPUTERNAME%.TXT


find /I "AcPrfMgrSvc" %COMPUTERNAME%_START.TXT >nul
IF ERRORLEVEL 1 NET START "AcPrfMgrSvc"
IF ERRORLEVEL 1 ECHO AcPrfMgrSvc >>%COMPUTERNAME%.TXT
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜