|
|
|
SC.exe (Resource Kit)
Service Control - Create, Create remotely, Start, Stop, Query,
Delete.
syntax
SC [\\server] [command] [service name] [OptionName=OptionValue...]
key
server : The machine where the service is running
service name : The KeyName of the service, this is often but not always
the same as the DisplayName shown in Control Panel, Services.
You can get the KeyName by running:
SC GetKeyName <DisplayName>
command (display service info)
query : Show status
queryEx : Show extended status information.##
GetDisplayName : Show the DisplayName
GetKeyName : Show the ServiceKeyName
EnumDepend : Show Dependencies
qc : Show configuration information
command (requests to change a service)
start : START a service.
stop : STOP a service
pause : PAUSE a service.
continue : CONTINUE a service.
create : Create a service. (add it to the registry)
config : permanently change the service configuration
delete : Delete a service (from the registry)
control : Send a control to a service.##
interrogate : Send an INTERROGATE control request to a service.##
Qdescription : Query the description of a service.##
description : Change the description of a service.##
Qfailure : Query the actions taken by a service upon failure.##
failure : Change the actions taken by a service upon failure.##
sdShow : Display a service's security descriptor using SDDL.##
SdSet : Sets a service's security descriptor using SDDL.##
misc commands (don't require a service name)
SC QueryLock : Query the LockStatus for the ServiceManager Database.
This will show if a service request is running
SC Lock : Lock the Service Database
SC BOOT : Values are {ok | bad} Indicates whether to save
the last restart configuration as the `last-known-good`
restart configuration. ##
## Option requires Windows 2K or above
The create and config commands have several additional options
for full details just enter:
SC create
SC config
The SC command duplicates some aspects of the NET command
but adds the ability to create a service and can run a query to see if a service
is running, giving output something like this:
SERVICE_NAME : messenger
TYPE : 20 WIN32_SHARE_PROCESS
STATE : 4 RUNNING
(STOPPABLE,NOT_PAUSABLE,ACCEPTS_SHUTDOWN)
WIN32_EXIT_CODE : 0 (0x0)
SERVICE_EXIT_CODE : 0 (0x0)
CHECKPOINT : 0x0
WAIT_HINT : 0x0
You can pipe the output into FIND in order to retrieve
specific sections of the above output e.g.
SC query messenger | FIND "RUNNING"
In the statement above the FIND command will set the ERRORLEVEL
as follows
ERRORLEVEL 0 = Running
ERRORLEVEL 1 = Stopped or Paused
The NET START command can be used in a similar way to
check if a service is running:
NET START | FIND "Service name" > nul IF errorlevel 1 GOTO :s_not_running
Examples:
SC GetKeyName "task scheduler"
SC GetDisplayName schedule
SC start schedule
SC query schedule
SC \\myServer CONFIG myService obj= LocalSystem password= mypassword
"There is always room at the top" - Daniel
Webster
Related Commands:
NET - manage network resources
SCLIST - Display NT Services
NETSVC - Command-line Service Controller (Win
2K ResKit)
START /HIGH - Start a specified program or command.
INSTSRV - Install an NT service (run under a specific account)
DELSRV - Delete NT service
Svcmon - Monitor services and raise an alert if they stop. (Win
2K ResKit)
Svcacls - Service ACL Editor (Win 2K ResKit)
WMIC SERVICE - WMI access to services.
List of Windows Services
Q251192 - Create a Windows
Service using SC
Q166819 - Control Services
Remotely
Q170738 - Debugging
a Windows NT Service
TechNet
- Using SC.EXE to develop Windows NT Services
Equivalent Linux BASH commands:
nice - Change job scheduling priority