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 are OK and BAD. 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 of type:
      • OWN - Service runs in its own process (default).
      • SHARE - Service shares a process with other services.
      • INTERACT - Service interacts via user input. Use with TYPE= OWN or TYPE= 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.
      Default is TYPE= OWN.
    • START= start - Specifies the startup type for the service to be configured. Instead of start:
      • 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 via SC START subcommand.
      • DELAYED-AUTO - Start automatically at each reboot, like AUTO, but delayed until higher-priority services start.
      Default is 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 is ERROR= 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 at HKLM\System\CurrentControlSet\Control\ServiceGroupOrder. The default value is GROUP= null.
    • TAG= {YES | NO} - Specifies whether to get the ID tag for drivers at bootloader or system startup (START= BOOT or START= 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 is OBJ= 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 if OBJ= LOCALSYSTEM is used.
  • CONTINUE - Resumes the specified service, if it was previously paused. See SC PAUSE.
  • CONTROL - Sends a control code to the specified service. Available options are PARAMCHANGE, 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 the SC CONFIG subcommand. Note that the BINPATH= 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, use RESET= INFINITE. This option should be used in conjunction with ACTIONS=.
    • 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 are RUN, RESTART, and REBOOT. Actions and delays are separated by the slash /. This option should be used in conjunction with RESET=.
  • FAILUREFLAG - Sets or changes the flag for actions to be taken in case of failure (see the SC FAILURE subcommand). If set to 0, actions are only triggered if the service is stopped with a status other than SERVICE_STOPPED. If set to 1, actions are also triggered if the exit status is SERVICE_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 to TRUE if you want to prompt for the password when the service starts, or to FALSE if you want to use the configured password (via SC CONFIG).
  • PAUSE - Pauses the specified service. Use SC 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 with SC 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 are SEBACKUPPRIVILEGE and SERESTOREPRIVILEGE.
  • QC - Queries the configuration information for the specified service (see SC CONFIG). The buffer size required for display can also be specified as an option.
  • QDESCRIPTION - Queries the description of the specified service (see SC 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 (see SC 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 (see SC 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 (see SC MANAGEDACCOUNT). The buffer size required for display can also be specified as an option.
  • QPREFERREDNODE - Queries the preferred NUMA node for the specified service (see SC PREFERREDNODE). The buffer size required for the display can also be specified as an option.
  • QPRIVS - Queries the privileges of the specified service (see SC 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 (see SC SIDTYPE). The buffer size required for display can also be specified as an option.
  • QTRIGGERINFO - Queries the trigger parameters of the specified service (see SC 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 is TYPE= SERVICE.
    • STATE= {INACTIVE | ACTIVE | ALL} - Specifies the state of services to list. The default is STATE= ACTIVE.
    • BUFSIZE= size - Specifies the size of the enumeration buffer in bytes. By default it is BUFSIZE= 1024 or BUFSIZE= 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 to RI= 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 the SC QUERY subcommand.
  • QUERYLOCK - Queries whether the specified service database is locked or not (see SC 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 to UNRESTRICTED, 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 format flag:major_reason:minor_reason along with a comment of up to 127 characters.
    Instead of flag:
    • 1 - Unplanned.
    • 2 - Custom.
    • 4 - Planned.
    Instead of major_reason:
    • 1 - Other.
    • 2 - Hardware.
    • 3 - Operating system.
    • 4 - Software.
    • 5 - Application.
    • 64-255 - Custom.
    Instead of 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 (type SC 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