SC
(from Service Control)
Manages and displays Windows services.
SC [\\server_name] [subcommand] [service] [option [...]]
Where:
\\server_name
- Specifies the server or remote system in UNC format whose services you want to manage. By default, it manages services on the local system.subcommand
- Indicates the action to perform.service
- Specifies the name of the service on which to perform the action. This argument is required for some subcommands, while optional or to be omitted for others.option [...]
- Specifies one or more options for the chosen subcommand or arguments for the service.
Instead of subcommand
:
BOOT
- Indicates whether the last boot should be saved as a valid configuration. Options areOK
andBAD
. This subcommand does not require a service parameter.CONFIG
- Modifies an entry for the specified service. Available options are:TYPE= type
- Specifies the type of service to associate with the service. Instead oftype
:OWN
- Service runs in its own process (default).SHARE
- Service shares a process with other services.INTERACT
- Service interacts via user input. Use withTYPE= OWN
orTYPE= SHARED
.KERNEL
- Kernel driver.FILESYS
- File system driver.REC
- Recognized file system driver.ADAPT
- Adapter driver, e.g., for keyboards, mice, disks.USEROWN
- Non-admin user service running in its own process.USERSHARE
- Non-admin user service sharing a process with others.
TYPE= OWN
.START= start
- Specifies the startup type for the service to be configured. Instead ofstart
:BOOT
- Start from boot loader.SYSTEM
- Start during kernel initialization.AUTO
- Start automatically at each reboot (even if no user logs in).DEMAND
- Manual startup (default).DISABLED
- Startup disabled. Prevents startup viaSC START
subcommand.DELAYED-AUTO
- Start automatically at each reboot, likeAUTO
, but delayed until higher-priority services start.
START= DEMAND
.ERROR= {NORMAL | SEVERE | CRITICAL | IGNORE}
- Specifies the criticality of the error if the service fails to start successfully. Normal mode warns the user of the error and continues booting, severe mode restores the configuration to a previous state and reboots the system, critical mode is like severe but blocks booting if the configuration restore fails, and ignore mode continues booting without warning the user. The default isERROR= NORMAL
.BINPATH= path
- Specifies the path to the service binary to configure.GROUP= groupname
- Specifies the group to associate with the service (the complete list can be found in the registry atHKLM\System\CurrentControlSet\Control\ServiceGroupOrder
. The default value isGROUP= null
.TAG= {YES | NO}
- Specifies whether to get the ID tag for drivers at bootloader or system startup (START= BOOT
orSTART= SYSTEM
).DEPEND= service1[/service2[/...]]
- Specifies the dependencies for the service to be configured, that is, the services on which it depends, separated by a slash/
.OBJ= name
- Specifies the name of the user account to associate with the service or the name of the Windows driver object. The default isOBJ= LOCALSYSTEM
.DISPLAYNAME= name
- Specifies a descriptive, easily readable name for the service to be configured.PASSWORD= password
- Specifies the password for the specified user account. This option is not needed ifOBJ= LOCALSYSTEM
is used.
CONTINUE
- Resumes the specified service, if it was previously paused. SeeSC PAUSE
.CONTROL
- Sends a control code to the specified service. Available options arePARAMCHANGE
,NETBINDADD
,NETBINDREMOVE
,NETBINDENABLE
,NETBINDDISABLE
, or a user-defined control code.CREATE
- Creates a service, adding it to the registry. The available options are the same as theSC CONFIG
subcommand. Note that theBINPATH= path
option is mandatory.DELETE
- Deletes a service by removing it from the registry.DESCRIPTION
- Sets or modifies the description of the specified service. The description must be entered as a subcommand option.ENUMDEPEND
- Displays services that depend on the specified service. You can also optionally specify the buffer size required for display.FAILURE
- Changes the actions performed by the specified service when an error is encountered. The available options are:RESET= time
- Specifies the amount of time, in seconds, that no errors occur before the error count is reset to 0. To set an indefinite time, useRESET= INFINITE
. This option should be used in conjunction withACTIONS=
.REBOOT= msg
- Specifies the message to display before rebooting if an error occurs.COMMAND= command
- Specifies a DOS command to execute on error.ACTIONS= action/delay[/action2/delay2[/...]]
- Specifies an action to take on an error followed by a delay in milliseconds associated with that action. The available actions areRUN
,RESTART
, andREBOOT
. Actions and delays are separated by the slash/
. This option should be used in conjunction withRESET=
.
FAILUREFLAG
- Sets or changes the flag for actions to be taken in case of failure (see theSC FAILURE
subcommand). If set to 0, actions are only triggered if the service is stopped with a status other thanSERVICE_STOPPED
. If set to 1, actions are also triggered if the exit status isSERVICE_STOPPED
and the application associated with the service returns a code other than 0.GETDISPLAYNAME
- Displays the descriptive name (display name) of the specified service. The buffer size required for display can also be specified as an option.GETKEYNAME
- Displays the key name of a service from its display name. The buffer size required for display can also be specified as an option.INTERROGATE
- Interrogates the specified service (INTERROGATE
control request).LOCK
- Locks the database of the specified service.MANAGEDACCOUNT
- Indicates whether the account under which the service runs uses a managed password. Set toTRUE
if you want to prompt for the password when the service starts, or toFALSE
if you want to use the configured password (viaSC CONFIG
).PAUSE
- Pauses the specified service. UseSC CONTINUE
to resume the service.PREFERREDNODE
- Sets or changes the preferred NUMA node for a specified service, with the node number as an option. Enter-1
to clear the setting. This subcommand is only valid in 32-bit (Win32) mode and for services with their own process (e.g. configured withSC CONFIG TYPE= OWN
).PRIVS
- Sets or changes the privileges of the specified service. Privileges must be specified as options separated by a slash/
. Examples of privileges areSEBACKUPPRIVILEGE
andSERESTOREPRIVILEGE
.QC
- Queries the configuration information for the specified service (seeSC CONFIG
). The buffer size required for display can also be specified as an option.QDESCRIPTION
- Queries the description of the specified service (seeSC DESCRIPTION
). The buffer size required for display can also be specified as an option.QFAILURE
- Queries the actions performed by the specified service when an error is encountered (seeSC FAILURE
). The buffer size required for the display can also be specified as an option.QFAILUREFLAG
- Queries the flag of the actions to be performed in case of error (seeSC FAILUREFLAG
). The buffer size required for the display can also be specified as an option.QMANAGEDACCOUNT
- Queries whether the account under which the service runs uses a managed password (seeSC MANAGEDACCOUNT
). The buffer size required for display can also be specified as an option.QPREFERREDNODE
- Queries the preferred NUMA node for the specified service (seeSC PREFERREDNODE
). The buffer size required for the display can also be specified as an option.QPRIVS
- Queries the privileges of the specified service (seeSC PRIVS
). The buffer size required for display can also be specified as an option.QPROTECTION
- Queries whether the service can be started in a protected process. Note that this setting cannot be changed.QSIDTYPE
- Queries the SID (security identifier) type of a specified service (seeSC SIDTYPE
). The buffer size required for display can also be specified as an option.QTRIGGERINFO
- Queries the trigger parameters of the specified service (seeSC TRIGGERINFO
). The buffer size required for display can also be specified as an option.QUERY
- Queries the status of a service or driver (if specified), or displays a list of the statuses of all active services (if no options are specified). If no service or driver is specified, the following options may apply:TYPE= {DRIVER | SERVICE | USERSERVICE | ALL}
- Specifies the type of services to list. Default isTYPE= SERVICE
.STATE= {INACTIVE | ACTIVE | ALL}
- Specifies the state of services to list. The default isSTATE= ACTIVE
.BUFSIZE= size
- Specifies the size of the enumeration buffer in bytes. By default it isBUFSIZE= 1024
orBUFSIZE= 4096
, depending on your version of Windows.RI= index
- Specifies the index from which to start or resume the service list. Note that the index starts at 0. By default this parameter is set toRI= 0
.GROUP= groupname
- Specifies the service group you want to list. By default, it lists all groups.
QUERYEX
- Queries the extended status of a service or driver (if specified), or lists the statuses of all services or drivers (if no options are specified). The available options are the same as those for theSC QUERY
subcommand.QUERYLOCK
- Queries whether the specified service database is locked or not (seeSC LOCK
).QUSERSERVICE
- Queries a user service instance in the same session created by the specified user service template.SDSET
- Sets the security descriptor. Optionally enter the security descriptor (SD) in SDDL format.SDSHOW
- Shows the security descriptor in SDDL format. Enter viewing rights as options.SHOWSID
- Shows the string associated with the SID of the specified service. Note that the SID depends only on the service name. It is possible to obtain the SID for a non-existent service.SIDTYPE
- Sets or changes the SID (Security Identifier) type of a service. Valid options are:NONE
- The service SID will not be added to the service process token.UNRESTRICTED
- The service SID is added to the process token the next time the service is started. Valid for services in 32-bit (Win32) mode.RESTRICED
- Similar toUNRESTRICTED
, but the SID is also added to the restricted SID list. In case of shared process, all services associated with the same process must have the same SID.
START
- Starts the specified service, adding any arguments as options.STOP
- Stops the specified service. The reason for the stop can be specified in the numeric formatflag:major_reason:minor_reason
along with a comment of up to 127 characters.
Instead offlag
:1
- Unplanned.2
- Custom.4
- Planned.
major_reason
:1
- Other.2
- Hardware.3
- Operating system.4
- Software.5
- Application.64
-255
- Custom.
minor_reason
:1
- Other.2
- Manutenzione.3
- Installation.4
- Update.5
- Reconfiguration.6
- Block.7
- Instability.8
- Disk.9
- Network card.10
- Environment.11
- Hardware drive.13
- Service pack.14
- Software update.15
- Hardware update.16
- Security.17
- Network connectivity.18
- WMI (Windows Management Instrumentation, see WMICWMIC).19
- Uninstalling service pack.20
- Uninstalling software update.22
- Uninstalling security update.23
- MMC (Microsoft Management Console).256
-65535
- Custom.
TRIGGERINFO
- Modify the trigger parameters of the specified service (typeSC TRIGGERINFO
for more information).
For all options that have an equals sign, you must insert a space between the equals sign and the value you want to specify.
Examples:
1. Create the selfservice
service with the descriptive name Self service
that runs the program C:\service\self.exe
automatically when the computer starts:
sc create selfservice binpath= "C:\service\self.exe" displayname= "Self service" start= auto
2. Start the selfservice
service:
sc start selfservice
3. Stop the selfservice
service by indicating unscheduled as flag, custom primary reason (64) and custom secondary reason (256), inserting the comment There's no more wine
:
sc stop selfservice 1:64:256 There's no more wine
4. Delete the selfservice
service:
sc delete selfservice
5. Display in detail all active services that are not part of a group:
sc queryex group= ""
Comments