How to Change a Service's Startup Type in Batch Script
The startup type of a Windows service determines how and when it starts. An Automatic service starts when the computer boots, a Demand (Manual) service only starts when it is explicitly told to, and a Disabled service cannot be started at all. As an administrator, you often need to change a service's startup type as part of a software installation, a security hardening script, or a troubleshooting process.
This guide will teach you how to use the standard, built-in SC.EXE (Service Control) utility to change the startup type of any service from a batch script. You will learn the different startup types and the critical requirement of running your script as an administrator.
The Core Command: SC CONFIG
The sc.exe utility is the primary command-line tool for all service management. To modify a service's properties, we use the config command.
The syntax for changing the startup type is: SC CONFIG "<ServiceName>" start=<StartupType>
CONFIG: The sub-command to configure a service's properties.<ServiceName>: The short, internal name of the service (not its Display Name).start=: The specific parameter we are changing.<StartupType>: The new startup mode you want to set.
This command must be run with administrator privileges.
The Startup Types Explained
You can set the start= parameter to one of four main values:
| Startup Type | Description |
|---|---|
auto | Automatic. The service starts when the computer boots up. |
delayed-auto | Automatic (Delayed Start). The service starts shortly after the system has finished booting, which can improve boot performance. |
demand | Manual. The service must be started manually (e.g., with NET START) or by another application. |
disabled | Disabled. The service cannot be started at all. |
Basic Example: Changing a Service to Disabled
Let's disable the "Windows Update" service (wuauserv). This is a common action during certain sensitive system maintenance tasks.
@ECHO OFF
REM This script MUST be run as an Administrator.
SET "ServiceName=wuauserv"
ECHO --- Changing Service Startup Type ---
ECHO.
ECHO Disabling the '%ServiceName%' service...
SC CONFIG "%ServiceName%" start=disabled
IF %ERRORLEVEL% EQU 0 (
ECHO [SUCCESS] The service startup type has been changed.
) ELSE (
ECHO [FAILURE] The command failed. Are you running as an Administrator?
)
How the Command Works
The SC CONFIG command directly modifies the registry values associated with the specified service, which are located under HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services. Specifically, it changes the Start value in the service's key. The Windows Service Control Manager reads this value at boot time and when a NET START command is issued to determine how to handle the service.
Common Pitfalls and How to Solve Them
Problem: The Script is Not Run as Administrator
This is the number one reason SC CONFIG fails. Modifying a system service is a highly privileged operation.
Example of error message:
[SC] OpenService FAILED 5:
Access is denied.
Solution: The script must be run from an elevated command prompt. Right-click your .bat file or cmd.exe and select "Run as administrator."
Problem: Using the Wrong Service Name
You must use the internal Service Name, not the friendly Display Name that you see in the services.msc graphical interface.
| Display Name | Service Name |
|---|---|
| Windows Update | wuauserv |
| Print Spooler | Spooler |
| Task Scheduler | Schedule |
Solution: Use the SC QUERY command to find the correct SERVICE_NAME.
C:\> SC QUERY | find "DISPLAY_NAME: Print Spooler"
DISPLAY_NAME: Print Spooler
C:\> SC QUERY Spooler | find "SERVICE_NAME"
SERVICE_NAME: Spooler
The script SC GETKEYNAME "Display Name" is also a great tool for this.
Problem: The Space After start= is Required
This is a quirky but critical syntax requirement of the SC command. If you omit the space after the equals sign, the command will fail.
Example of script with error:
REM This is WRONG and will fail.
SC CONFIG "MyService" start=auto
Example of correct script:
REM This is CORRECT. Note the space after start=
SC CONFIG "MyService" start= auto
For delayed-auto, demand, and disabled, the space is also required.
Practical Example: A Security Hardening Script
This script is designed to disable several services that are often considered non-essential in a secure server environment, reducing the system's attack surface.
@ECHO OFF
SETLOCAL
TITLE Security Hardening Script
REM This script must be run as an Administrator.
ECHO --- Disabling Non-Essential Services ---
ECHO This script will change the startup type of several services to 'Disabled'.
ECHO.
PAUSE
REM --- A pseudo-array of services to disable ---
SET "ServicesToDisable=Fax PrintNotify lmhosts"
FOR %%S IN (%ServicesToDisable%) DO (
ECHO.
ECHO Disabling service: %%S...
SC CONFIG "%%S" start= disabled
)
ECHO.
ECHO --- Hardening complete ---
ENDLOCAL
Conclusion
The SC CONFIG command is the definitive tool for programmatically changing a service's startup type. It provides complete control over how services are started, making it an essential command for any administrative batch script.
Key takeaways for using it successfully:
- You must run the script as an Administrator.
- Use the syntax
SC CONFIG "ServiceName" start= <StartupType>. - Remember the critical space after the equals sign (e.g.,
start= auto). - Always use the correct internal Service Name, which you can find with
SC QUERY.