@echo off
rem -- Script by Eric Berlin (ECJB1969) <ecjb@ecjb.net> 8/30/2024
rem -- Services list and settings source:
rem -- https://thegeekpage.com/restore-all-windows-services-to-default/
rem -- NOTE: This text file required some cleanup to be usable in this
rem -- script - there may still be stray spaces and odd characters
rem -- in the data text file.
rem -- NOTE: This service list and information is targeted to Win11.
rem -- It may or may not work as expected on other versions of Windows.
rem -- The accompanying text file contains the following tab-delimited fields:
rem -- Service name, sc.exe startup type, service short name,
rem -- Services.msc startup type, and Service normally running
rem -- The SC startup types are as follows:
rem -- start= <boot|system|auto|demand|disabled|delayed-auto>
rem -- "boot" and "system" services are not in this list.
rem -- The other startup types correspond to the Services MMC snap-in:
rem -- Automatic|Manual|Disabled|Automatic (Delayed start)
rem -- NOTE: Some of these services can not be set using sc.exe to configure
rem -- them and will generate errors. You may wish to capture the ones that
rem -- did not work and open SERVICES.MSC and check them manually.
cls
rem -- Check if admin.
net session 2> nul:
if errorlevel 1 (
echo This script must be run as an administrator.
echo You are not running this script with admin privileges.
pause
goto :eof
)
pushd "%~dp0"
rem -- Check for accompanying text file in this directory.
if not exist "%~n0.txt" (
echo This script looks for a tab-delimited text file of the same name in the
echo current directory. The file %~n0.txt was not found.
pause
goto :eof
)
rem -- Parse the text file and generate SC.exe commands to set the startup type
rem -- and optionally start the service (if not running and it should be).
for /f "tokens=1-5 delims= " %%a in (%~n0.txt) do (
rem -- Setting the default startup type for Windows services
echo Setting %%a / %%c to startup type %%d...
rem -- Use the short/canonical name with SC.exe. The long name may not work properly.
sc config %%c start= %%b
rem -- If the "Running" field has a value, check if the service is running.
rem -- If not, attempt to start it.
if not "%%e" == "" (
for /f "tokens=1,4" %%m in ('sc query "%%c"') do (
if /i "%%m" == "State" (
if /i "%%n" neq "Running" (
rem -- If the status does not say running and it should be, start the service.
echo Attempting to start service %%a / %%c...
sc start %%c
)
)
)
)
)
echo.
echo All done...
pause
popd