How do I restart a service from the command line?
8:56 AM
To restart a service from the command line, you can use one of two methods both from a command line window:
Example Code - Stop a Service
C:\>net stop w32time
The Windows Time service is stopping.
The Windows Time service was stopped successfully.
Example Code - Start a Service
C:\>net start w32time
The Windows Time service is starting.
The Windows Time service was started successfully.
In order to use the command line option, you must know the service
name in order to enter in the command line information correctly. Aside
from that, both commands achieve virtually the same thing. The only
difference is that the "sc" command has more functionality that can be
utilized.
Using the SC Command
Example Code - Stop a Service
C:\>sc stop w32time
SERVICE_NAME: w32time
TYPE : 10 WIN32_OWN_PROCESS
STATE : 3 STOP_PENDING
(STOPPABLE, PAUSABLE, ACCEPTS_SHUTDOWN)
WIN32_EXIT_CODE : 0 (0x0)
SERVICE_EXIT_CODE : 0 (0x0)
CHECKPOINT : 0x0
WAIT_HINT : 0x0
Example Code- Start a Service
C:\>sc start w32time
SERVICE_NAME: w32time
TYPE : 10 WIN32_OWN_PROCESS
STATE : 2 START_PENDING
(NOT_STOPPABLE, NOT_PAUSABLE, IGNORES_SHUTDOWN))
WIN32_EXIT_CODE : 0 (0x0)
SERVICE_EXIT_CODE : 0 (0x0)
CHECKPOINT : 0x0
WAIT_HINT : 0x7d0
PID : 3596
FLAGS :
Example Code - Query a Service's Status
C:\>sc query w32time
SERVICE_NAME: w32time
TYPE : 10 WIN32_OWN_PROCESS
STATE : 4 RUNNING
(STOPPABLE, PAUSABLE, ACCEPTS_SHUTDOWN)
WIN32_EXIT_CODE : 0 (0x0)
SERVICE_EXIT_CODE : 0 (0x0)
CHECKPOINT : 0x0
WAIT_HINT : 0x0
C:\>sc stop w32time
SERVICE_NAME: w32time
TYPE : 10 WIN32_OWN_PROCESS
STATE : 3 STOP_PENDING
(STOPPABLE, PAUSABLE, ACCEPTS_SHUTDOWN)
WIN32_EXIT_CODE : 0 (0x0)
SERVICE_EXIT_CODE : 0 (0x0)
CHECKPOINT : 0x0
WAIT_HINT : 0x0
Example Code- Start a Service
C:\>sc start w32time
SERVICE_NAME: w32time
TYPE : 10 WIN32_OWN_PROCESS
STATE : 2 START_PENDING
(NOT_STOPPABLE, NOT_PAUSABLE, IGNORES_SHUTDOWN))
WIN32_EXIT_CODE : 0 (0x0)
SERVICE_EXIT_CODE : 0 (0x0)
CHECKPOINT : 0x0
WAIT_HINT : 0x7d0
PID : 3596
FLAGS :
Example Code - Query a Service's Status
C:\>sc query w32time
SERVICE_NAME: w32time
TYPE : 10 WIN32_OWN_PROCESS
STATE : 4 RUNNING
(STOPPABLE, PAUSABLE, ACCEPTS_SHUTDOWN)
WIN32_EXIT_CODE : 0 (0x0)
SERVICE_EXIT_CODE : 0 (0x0)
CHECKPOINT : 0x0
WAIT_HINT : 0x0
Using the net Command
Example Code - Stop a Service
C:\>net stop w32time
The Windows Time service is stopping.
The Windows Time service was stopped successfully.
Example Code - Start a Service
C:\>net start w32time
The Windows Time service is starting.
The Windows Time service was started successfully.
0 comments