How can I check the existence of a Windows service in a batch 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