如何检查批处理文件中是否存在Windows服务?
用户正在输入服务名称,我想在继续编写脚本之前检查服务是否存在。
答案 0 :(得分:1)
试试这个:
>NET START | FIND "Workstation"
其中“Workstation”是服务的名称
答案 1 :(得分:1)
@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