Skip to main content

How to Pause and Resume a Service in a Batch Script

While start and stop are the most common actions for managing Windows services, some services also support a "paused" state. A paused service is still running, but it temporarily suspends its main functions and will not accept new client connections or process new work. This is a useful administrative state that allows you to perform maintenance or backups without fully stopping the service and its dependencies.

This guide will teach you how to use the built-in NET.EXE and SC.EXE commands to pause and resume (continue) a service from a batch script. You will learn the correct syntax and the critical importance of running the script with administrator privileges.

The Core Commands: NET PAUSE and NET CONTINUE

The NET.EXE utility is a classic, high-level tool for managing network resources, including services. Its syntax for this task is simple and readable.

To Pause a Service: NET PAUSE "ServiceName"

To Resume (Continue) a Service: NET CONTINUE "ServiceName"

  • "ServiceName": This is the internal service name, not the longer "Display Name." This is a crucial distinction.

An Alternative: Using SC.EXE

The SC.EXE (Service Control) utility is a more powerful, lower-level tool for managing services. It can also pause and continue services.

To Pause a Service: SC PAUSE "ServiceName"

To Resume (Continue) a Service: SC CONTINUE "ServiceName"

NET vs. SC: For the simple tasks of pausing and continuing, both commands are equally effective. NET is sometimes preferred for its slightly more user-friendly messages, while SC is often seen as the more "administrative" tool. You can use whichever you prefer.

How to Check if a Service Can Be Paused

Not all services can be paused. This functionality must be explicitly built into the service's code by its developer. If you try to pause a service that doesn't support it, you will get an error.

You can check if a service is pausable by querying its status with sc query.

C:\> sc query Spooler

Look at the STATE line in the output. It will list all the actions the service can accept.

SERVICE_NAME: Spooler
...
STATE : 4 RUNNING
(STOPPABLE, NOT_PAUSABLE, ACCEPTS_SHUTDOWN)
...

Here, the Print Spooler (Spooler) is NOT_PAUSABLE. The "Server" service (lanmanserver), however, is pausable.

Basic Example: Pausing and Resuming the "Server" Service

The "Server" service is responsible for file, print, and named-pipe sharing. Pausing it is a common way to temporarily block new share connections without fully stopping dependent services. Its service name is lanmanserver.

@ECHO OFF
REM This script MUST be run as an Administrator.

SET "ServiceName=lanmanserver"

ECHO --- Pausing the '%ServiceName%' service ---
PAUSE
NET PAUSE %ServiceName%

ECHO.
ECHO The service is now paused. New connections will be blocked.
ECHO Check its status now in services.msc.
PAUSE

ECHO.
ECHO --- Resuming the '%ServiceName%' service ---
NET CONTINUE %ServiceName%

ECHO.
ECHO The service is now running normally again.

Common Pitfalls and How to Solve Them

  • Administrator Rights: This is the number one cause of failure. You will get an "Access is denied" error if your script is not run from an elevated command prompt. Solution: You must run the script as an Administrator.

  • Service Name vs. Display Name: As with all service management commands, you must use the short, internal Service Name.

    • NET PAUSE "Server" -> WRONG (This is the Display Name)
    • NET PAUSE lanmanserver -> CORRECT
    • Solution: Use sc queryex to find the correct service name before scripting.
  • Service Does Not Support Pausing: If you try to pause a service that is NOT_PAUSABLE, the command will fail.

    • The Error: The requested pause, continue, or stop is not valid for this service.
    • Solution: Check the service's capabilities with sc query first. Your script should only attempt to pause services that are known to support it.

Practical Example: A Safe Backup Script

This script prepares for a backup of a database. The database service allows pausing, which flushes its caches to disk and blocks new connections, ensuring a safe and consistent backup.

@ECHO OFF
SETLOCAL
REM This script MUST be run as an Administrator.

SET "DbServiceName=MyCustomSQLService"

ECHO --- Safe Database Backup Script ---
ECHO.

ECHO Checking service status...
sc query "%DbServiceName%" | FIND "STATE" | FIND "RUNNING" > NUL
IF %ERRORLEVEL% NEQ 0 (
ECHO [ERROR] The database service is not running. Aborting backup.
GOTO :End
)

sc query "%DbServiceName%" | FIND "PAUSABLE" > NUL
IF %ERRORLEVEL% NEQ 0 (
ECHO [ERROR] The database service cannot be paused. Aborting backup.
GOTO :End
)

ECHO.
ECHO Step 1: Pausing the database service to ensure a consistent state...
SC PAUSE "%DbServiceName%"
ECHO.

ECHO Step 2: Running the backup...
REM (Your backup command, e.g., robocopy, would go here)
ECHO Simulating backup for 10 seconds...
TIMEOUT /T 10 > NUL
ECHO Backup complete.
ECHO.

ECHO Step 3: Resuming the database service...
SC CONTINUE "%DbServiceName%"

ECHO.
ECHO [SUCCESS] Backup finished and service is running normally.

:End
ENDLOCAL

Conclusion

The NET PAUSE and NET CONTINUE (or SC PAUSE/SC CONTINUE) commands are important tools for service management, allowing you to temporarily suspend a service's activity without fully stopping it.

For reliable scripting:

  1. Always run your script as an Administrator.
  2. Use sc query first to verify that the service is PAUSABLE.
  3. Use the correct internal Service Name, not the Display Name.
  4. Use NET PAUSE or SC PAUSE to pause the service.
  5. Use NET CONTINUE or SC CONTINUE to resume it.

This technique is essential for any administrative script that needs to perform maintenance on systems with pausable services, such as database servers or file servers.