How to Start a Service in a Batch Script
Windows services are background processes that provide core operating system functions and run applications without a user interface. Administrators and scripts often need to start a service that has been stopped for maintenance, is set to a manual start type, or has failed to start on its own.
This guide will teach you how to start a Windows service from a batch script using the two primary built-in commands for this task: the simple NET START and the more powerful and script-oriented SC START. You will learn the difference between them, the critical importance of using the correct service name, and how to write a robust script that checks a service's status before acting.
CRITICAL NOTE: Starting or stopping system services is a privileged operation. You must run any script that manages services with full administrator privileges.
The Core Commands: NET START and SC START
Windows provides two commands for starting services, each with its own characteristics.
NET START
This is a high-level, user-friendly command.
Syntax: NET START "Service Name"
- Its main advantage is that it often works with the long, user-friendly Display Name (e.g., "Print Spooler").
- It is simple and provides clear feedback.
SC START (Recommended for Scripting)
This is the more powerful and precise Service Control utility.
Syntax: SC START ServiceName
- This command requires the short, internal Service Name (e.g.,
Spooler). - It is the more robust and consistent choice for automation and is part of a larger toolset (
sccan alsostop,query,config,delete, etc.). - It is the only command that can pass startup arguments to a service.
Basic Example: Starting a Service
Let's start the "Print Spooler" service, which is often stopped for troubleshooting. Its display name is "Print Spooler" and its service name is Spooler.
Method 1: Using NET START
@ECHO OFF
REM This script MUST be run as an Administrator.
ECHO Starting the Print Spooler using NET START...
NET START "Print Spooler"
Method 2: Using SC START
@ECHO OFF
REM This script MUST be run as an Administrator.
ECHO Starting the Print Spooler using SC START...
SC START Spooler
Both commands will start the service, but SC START is generally preferred for its consistency in scripting.
The Essential Prerequisite: Finding the Correct Service Name
The most common reason a script fails is that it uses the wrong name for the service. SC START requires the internal service name.
The best way to find the correct name is with sc queryex.
Command to Find a Service: sc queryex type=service state=all | findstr /I "Display Name To Find"
Example
C:\> sc queryex type=service state=all | findstr /I "Print Spooler"
DISPLAY_NAME: Print Spooler
SERVICE_NAME: Spooler
This output clearly shows you that the Display Name is "Print Spooler" and the Service Name required by sc is Spooler.
Passing Arguments to a Service (SC START only)
Some services are designed to accept arguments when they start. The NET START command cannot do this. Only SC START can pass these parameters.
Syntax: SC START ServiceName [arg1] [arg2] ...
Example
REM This starts a custom service and passes it a configuration file path.
SC START MyCustomService --config="C:\AppData\prod.xml"
Common Pitfalls and How to Solve Them
-
Administrator Rights: This is the number one cause of failure. You will receive an "Access is denied" (Error 5) if your script is not run from an elevated command prompt. Solution: You must run the script as an Administrator.
-
Using the Wrong Name: As detailed above, using the "Display Name" with
SC STARTwill fail with an error: "The specified service does not exist as an installed service." Solution: Always usesc queryexto find the correct internal Service Name first. -
Service is Disabled: If a service's startup type is set to "Disabled," neither
NET STARTnorSC STARTcan start it.- The Error:
The service is disabled or it has no enabled devices associated with it. - Solution: Your script must first change the service's configuration to "Manual" or "Auto" before it can be started.
sc config ServiceName start=demand(for Manual)
- The Error:
Practical Example: A "Start If Stopped" Script
This is a very common and useful script for system monitoring or application launchers. It checks if a service is running and only starts it if it is currently stopped.
@ECHO OFF
SETLOCAL
REM This script must be run as an Administrator.
SET "ServiceName=wuauserv"
SET "ServiceDispName=Windows Update"
ECHO --- Service Health Check for %ServiceDispName% ---
ECHO.
REM Query the service and check if its STATE is "RUNNING".
sc query "%ServiceName%" | FIND "STATE" | FIND "RUNNING" > NUL
IF %ERRORLEVEL% EQU 0 (
ECHO [INFO] The "%ServiceDispName%" service is already running.
) ELSE (
ECHO [ACTION] The "%ServiceDispName%" service is stopped. Starting it now...
SC START "%ServiceName%"
)
ECHO.
ECHO --- Check complete ---
ENDLOCAL
Conclusion
Starting a service from a batch script is a straightforward task with the right commands.
NET STARTis simple and good for quick, interactive tasks.SC STARTis the powerful, robust, and recommended tool for all automation and scripting. It is more consistent and offers more features like passing arguments.
For reliable service management:
- Always run your script as an Administrator.
- Use
sc queryexto find the correct internal Service Name. - For robust scripts, check the service's state with
sc querybefore attempting to start it.