Freigeben über


SC

Communicates with the Service Controller and installed services. SC.exe retrieves and sets control information about services. You can use SC.exe for testing and debugging service programs. Service properties stored in the registry can be set to control how service applications are started at boot time and run as background processes. SC.exe parameters can configure a specific service, retrieve the current status of a service, as well as stop and start a service. You can create batch files that call various SC.exe commands to automate the startup or shutdown sequence of services. SC.exe provides capabilities similar to Services in the Administrative Tools item in Control Panel.

For the command syntax, click any of the following sc commands:

sc boot

Indicates whether the last boot should be saved as the last-known-good configuration.

Syntax

sc [ServerNameboot [{bad|OK}]

Parameters

ServerName   : Specifies the name of the remote server on which the service is located. The name must use the Universal Naming Convention (UNC) format ("\\myserver"). To run SC.exe locally, ignore this parameter.

[{ bad | OK }] : Specifies whether the last boot was bad or whether it should be saved as the last-known-good boot configuration.

/? : Displays help at the command prompt.

Examples

The following examples show how you can use the sc boot command:

sc boot ok
sc boot bad

sc config 

Modifies the value of a service's entries in the registry and in the Service Control Manager's database.

Syntax

sc [ServerNameconfig [ServiceName] [type= {own|share|kernel|filesys|rec|adapt|interact type= {own|share}}] [start= {boot|system|auto|demand|disabled}] [error= {normal|severe|critical|ignore}] [binpath= BinaryPathName] [group= LoadOrderGroup] [tag= {yes|no}] [depend= dependencies] [obj= {AccountName|ObjectName}] [displayname= DisplayName] [password= Password]

Parameters

ServerName   : Specifies the name of the remote server on which the service is located. The name must use the Universal Naming Convention (UNC) format ("\\myserver"). To run SC.exe locally, ignore this parameter.

ServiceName   : Specifies the service name returned by the getkeyname operation.

type= { own | share | kernel | filesys | rec | adapt | interact   type= { own | share }}   : Specifies the service type.

Value

Description

own

The service runs in its own process. It does not share an executable file with other services. This is the default.

share

The service runs as a shared process. It shares an executable file with other services.

kernel

Driver.

filesys

File system driver.

rec

File system-recognized driver (identifies file systems used on the computer).

adapt

Adapter driver (identifies hardware items such as keyboard, mouse, and disk drive).

interact

The service can interact with the desktop, receiving input from users. Interactive services must be run under the LocalSystem account. This type must be used in conjunction with type= own or type= shared (for example, type= interact type= own). Using type= interact by itself will generate an invalid parameter error.

start= { boot | system | auto | demand | disabled } : Specifies the start type for the service.

Value

Description

boot

A device driver that is loaded by the boot loader.

system

A device driver that is started during kernel initialization.

auto

A service that automatically starts each time the computer is restarted and runs even if no one logs on to the computer.

demand

A service that must be manually started. This is the default value if start= is not specified.

disabled

A service that cannot be started. To start a disabled service, change the start type to some other value.

error= { normal | severe | critical | ignore } : Specifies the severity of the error if the service fails to start during boot.

Value

Description

normal

The error is logged and a message box is displayed informing the user that a service has failed to start. Startup will continue. This is the default setting.

severe

The error is logged (if possible). The computer attempts to restart with the last-known-good configuration. This could result in the computer being able to restart, but the service may still be unable to run.

critical

The error is logged (if possible). The computer attempts to restart with the last-known-good configuration. If the last-known-good configuration fails, startup also fails, and the boot process halts with a Stop error.

ignore

The error is logged and startup continues. No notification is given to the user beyond recording the error in the Event Log.

binpath=   BinaryPathName   : Specifies a path to the service binary file.

group=   LoadOrderGroup   : Specifies the name of the group of which this service is a member. The list of groups is stored in the registry in the HKLM\System\CurrentControlSet\Control\ServiceGroupOrder subkey. The default is null.

tag= { yes | no } : Specifies whether or not to obtain a TagID from the CreateService call. Tags are only used for boot-start and system-start drivers.

depend=   dependencies   : Specifies the names of services or groups which must start before this service. The names are separated by forward slashes (/).

obj= { AccountName | ObjectName } : Specifies a name of an account in which a service will run, or specifies a name of the Windows driver object in which the driver will run. The default is LocalSystem.

displayname=   DisplayName   : Specifies a friendly, meaningful name that can be used in user-interface programs to identify the service to users. For example, the subkey name of one service is wuauserv, which is not be helpful to the user, and the display name is Automatic Updates.

password=   Password   : Specifies a password. This is required if an account other than the LocalSystem account is used.

/? : Displays help at the command prompt.

Remarks

  • Without a space between a parameter and its value (for example, type= own, not type=own), the operation will fail.

Examples

The following example shows how you can use the sc config command:

sc config NewService binpath= "ntsd -d c:\windows\system32\NewServ.exe"

sc continue

Sends a CONTINUE control request to a service in order to resume a paused service.

Syntax

sc [ServerNamecontinue [ServiceName]

Parameters

ServerName   : Specifies the name of the remote server on which the service is located. The name must use the UNC format ("\\myserver"). To run SC.exe locally, ignore this parameter.

ServiceName   : Specifies the service name returned by the getkeyname operation.

/? : Displays help at the command prompt.

Remarks

  • Use the continue operation to resume a paused service.

Examples

The following example shows how you can use the sc continue command:

sc continue tapisrv

sc control

Sends a CONTROL B to a service.

Syntax

sc [ServerNamecontrol [ServiceName] [{paramchange|netbindadd|netbindremove|netbindenable|netbinddisable|UserDefinedControlB}]

Parameters

ServerName   : Specifies the name of the remote server on which the service is located. The name must use the UNC format ("\\myserver"). To run SC.exe locally, ignore this parameter.

ServiceName   : Specifies the service name returned by the getkeyname operation.

{ paramchange | netbindadd | netbindremove | netbindenable | netbinddisable | UserDefinedControlB } : Specifies a control to send to a service.

/? : Displays help at the command prompt.

sc create

Creates a subkey and entries for the service in the registry and in the Service Control Manager's database.

Syntax

sc [ServerNamecreate [ServiceName] [type= {own|share|kernel|filesys|rec|adapt|interact type= {own|share}}] [start= {boot|system|auto|demand|disabled}] [error= {normal|severe|critical|ignore}] [binpath= BinaryPathName] [group= LoadOrderGroup] [tag= {yes|no}] [depend= dependencies] [obj= {AccountName|ObjectName}] [displayname= DisplayName] [password= Password]

Parameters

ServerName   : Specifies the name of the remote server on which the service is located. The name must use the UNC format ("\\myserver"). To run SC.exe locally, ignore this parameter.

ServiceName   : Specifies the service name returned by the getkeyname operation.

type= { own | share | kernel | filesys | rec | adapt | interact   type= { own | share }}   : Specifies the service type. The default is type= own.

Value

Description

own

The service runs in its own process. It does not share an executable file with other services. This is the default.

share

The service runs as a shared process. It shares an executable file with other services.

kernel

Driver.

filesys

File system driver.

rec

File system recognized driver (identifies file systems used on the computer).

interact

The service can interact with the desktop, receiving input from users. Interactive services must be run under the LocalSystem account. This type must be used in conjunction with type= own or type= shared (that is, type= interact type= own). Using type= interact by itself will generate an invalid parameter error.

start= { boot | system | auto | demand | disabled } : Specifies the start type for the service. The default start is start= demand.

boot

A device driver that is loaded by the boot loader.

system

A device driver that is started during kernel initialization.

auto

A service that automatically starts each time the computer is restarted and runs even if no one logs on to the computer.

demand

A service that must be manually started. This is the default value if start= is not specified.

disabled

A service that cannot be started. To start a disabled service, change the start type to some other value.

error= { normal | severe | critical | ignore } : Specifies the severity of the error if the service fails to start during boot. The default is error= normal.

normal

The error is logged and a message box is displayed informing the user that a service has failed to start. Startup will continue. This is the default setting.

severe

The error is logged (if possible). The computer attempts to restart with the last-known-good configuration. This could result in the computer being able to restart, but the service may still be unable to run.

critical

The error is logged (if possible). The computer attempts to restart with the last-known-good configuration. If the last-known-good configuration fails, startup also fails, and the boot process halts with a Stop error.

ignore

The error is logged and startup continues. No notification is given to the user beyond recording the error in the Event Log.

binpath=   BinaryPathName   : Specifies a path to the service binary file. There is no default for binpath= and this string must be supplied.

group=   LoadOrderGroup   : Specifies the name of the group of which this service is a member. The list of groups is stored in the registry in the HKLM\System\CurrentControlSet\Control\ServiceGroupOrder subkey. The default is null.

tag= { yes | no } : Specifies whether or not to obtain a TagID from the CreateService call. Tags are only used for boot-start and system-start drivers.

depend=   dependencies   : Specifies the names of services or groups that must start before this service. The names are separated by forward slashes (/).

obj= { AccountName | ObjectName } : Specifies a name of an account in which a service will run, or specifies a name of the Windows driver object in which the driver will run.

displayname=   DisplayName   : Specifies a friendly name that can be used by user-interface programs to identify the service.

password=   Password   : Specifies a password. This is required if an account other than LocalSystem is used.

/? : Displays help at the command prompt.

Remarks

  • Without a space between a parameter and its value (that is, type= own, not type=own), the operation will fail.

Examples

The following examples show how you can use the sc create command:

sc \\myserver create NewService binpath= c:\windows\system32\NewServ.exe
sc create NewService binpath= c:\windows\system32\NewServ.exe type= share start= auto depend= "+TDI Netbios"

sc delete

Deletes a service subkey from the registry. If the service is running or if another process has an open handle to the service, then the service is marked for deletion.

Syntax

sc [ServerNamedelete [ServiceName]

Parameters

ServerName   : Specifies the name of the remote server on which the service is located. The name must use the UNC format ("\\myserver"). To run SC.exe locally, ignore this parameter.

ServiceName   : Specifies the service name returned by the getkeyname operation.

/? : Displays help at the command prompt.

Remarks

  • Use Add or Remove Programs to delete DHCP, DNS, or any other built-in operating system services. Add or Remove Programs will not only remove the registry subkey for the service, but it will also uninstall the service and delete any shortcuts to the service.

Examples

The following example shows how you can use the sc delete command:

sc delete newserv

sc description

Sets the description string for a service.

Syntax

sc [ServerNamedescription [ServiceName] [Description]

Parameters

ServerName   : Specifies the name of the remote server on which the service is located. The name must use the UNC format ("\\myserver"). To run SC.exe locally, ignore this parameter.

ServiceName   : Specifies the service name returned by the getkeyname operation.

Description   : Specifies a description for the specified service. If no string is specified, the description of the service is not modified. There is no limit to the number of characters that can be contained in the service description.

/? : Displays help at the command prompt.

Examples

The following example shows how you can use the sc description command:

sc description newserv "Runs quality of service control."

sc enumdepend

Lists the services that cannot run unless the specified service is running.

Syntax

sc [ServerNameenumdepend [ServiceName] [BufferSize]

Parameters

ServerName   : Specifies the name of the remote server on which the service is located. The name must use the UNC format ("\\myserver"). To run SC.exe locally, ignore this parameter.

ServiceName   : Specifies the service name returned by the getkeyname operation.

BufferSize   : Specifies the size (in bytes) of the enumeration buffer. The default is 1024 bytes.

/? : Displays help at the command prompt.

Remarks

  • If the buffer is not big enough, the enumdepend operation will output dependencies only partially, and will specify the additional buffer size required to output all dependencies. If the output is truncated, rerun the operation and specify the larger buffer size.

Examples

The following examples show how you can use the sc enumdepend command:

sc enumdepend rpcss 5690
sc enumdepend tapisrv

sc failure

Specifies what action to take upon failure of the service.

Syntax

sc [ServerNamefailure [ServiceName] [reset= ErrorFreePeriod] [reboot= BroadcastMessage] [command= CommandLine] [actions= FailureActionsAndDelayTime]

Parameters

ServerName   : Specifies the name of the remote server on which the service is located. The name must use the UNC format ("\\myserver"). To run SC.exe locally, ignore this parameter.

ServiceName   : Specifies the service name returned by the getkeyname operation.

reset=   ErrorFreePeriod   : Specifies the length of the period (in seconds) with no failures after which the failure count should be reset to 0. This parameter must be used in conjunction with the actions= parameter.

reboot=   BroadcastMessage   : Specifies the message to be broadcast upon failure of the service.

command=   CommandLine   : Specifies the command line to be run upon failure of the service. For more information about how to run a batch or VBS file upon failure, see Remarks.

actions=   FailureActionsAndDelayTime   : Specifies the failure actions and their delay time (in milliseconds) separated by the forward slash (/). The following actions are valid: run, restart, and reboot. This parameter must be used in conjunction with the reset= parameter. Use actions= "" to take no action upon failure.

/? : Displays help at the command prompt.

Remarks

  • Not all services allow changes to their failure options. Some run as part of a service set.

  • To run a batch file upon failure, specify cmd**.exe** Drive**:\FileName.bat** to the command= parameter, where Drive**:\FileName.bat** is the fully qualified name of the batch file.

  • To run a VBS file upon failure, specify cscript drive**:\myscript.vbs** to the command= parameter, where drive**:\myscript.vbs** is the fully qualified name of the script file.

  • It is possible to specify three different actions to the actions= parameter, which will be used the first, second, and third time a service fails.

  • Without a space between a parameter and its value (that is, type= own, not type=own), the operation will fail.

Examples

The following examples show how you can use the sc failure command:

sc failure msftpsvc reset= 30 actions= restart/5000
sc failure dfs reset= 60 command= c:\windows\services\restart_dfs.exe actions= run/5000
sc failure dfs reset= 60 actions= reboot/30000
sc failure dfs reset= 60 reboot= "The Distributed File System service has failed. Because of this, the computer will reboot in 30 seconds." actions= reboot/30000
sc failure myservice reset= 3600 reboot= "MyService crashed -- rebooting machine" command= " %windir% \MyServiceRecovery.exe" actions= restart/5000/run/10000/reboot/60000

sc getdisplayname

Gets the display name associated with a particular service.

Syntax

sc [ServerNamegetdisplayname [ServiceName] [BufferSize]

Parameters

ServerName   : Specifies the name of the remote server on which the service is located. The name must use the UNC format ("\\myserver"). To run SC.exe locally, ignore this parameter.

ServiceName   : Specifies the service name returned by the getkeyname operation.

BufferSize   : Specifies the size (in bytes) of the buffer. The default is 1024 bytes.

/? : Displays help at the command prompt.

Examples

The following examples show how you can use the sc getdisplayname command:

sc getdisplayname clipsrv
sc getdisplayname tapisrv
sc getdisplayname sharedaccess

sc getkeyname

Gets the key name associated with a particular service, using the display name as input.

Syntax

sc [ServerNamegetkeyname [ServiceDisplayName] [BufferSize]

Parameters

ServerName   : Specifies the name of the remote server on which the service is located. The name must use the UNC format ("\\myserver"). To run SC.exe locally, ignore this parameter.

ServiceDisplayName   : Specifies the display name of the service.

BufferSize   : Specifies the size (in bytes) of the buffer. The default is 1024 bytes.

/? : Displays help at the command prompt.

Remarks

  • If the ServiceDisplayName contains spaces, use quotation marks around the text (that is, "Service Display Name").

Examples

The following examples show how you can use the sc getkeyname command:

sc getkeyname "remote procedure call (rpc)"
sc getkeyname "internet connection sharing"
sc getkeyname clipbook

sc interrogate

Sends an INTERROGATE control request to a service.

Syntax

sc [ServerNameinterrogate [ServiceName]

Parameters

ServerName   : Specifies the name of the remote server on which the service is located. The name must use the UNC format ("\\myserver"). To run SC.exe locally, ignore this parameter.

ServiceName   : Specifies the service name returned by the getkeyname operation.

/? : Displays help at the command prompt.

Remarks

  • Sending INTERROGATE to a service causes the service to update its status with the Service Control Manager.

Examples

The following examples show how you can use the sc interrogate command:

sc interrogate sharedaccess
sc interrogate rpcss

sc lock

Locks the Service Control Manager's database.

Syntax

sc [ServerName] lock

Parameters

ServerName   : Specifies the name of the remote server on which the service is located. The name must use the UNC format ("\\myserver"). To run SC.exe locally, ignore this parameter.

/? : Displays help at the command prompt.

Remarks

  • Locking the Service Control Manager's database prevents any services from starting. Use this if you want to make sure that a service will not be started after it has been stopped. This will allow you to take some action (for example, deleting the service) without interference.

  • Using the lock operation locks the Service Control Manager's database and then allows the database to be unlocked by typing u. You can also kill the process from which you locked the database.

Examples

The following example shows how you can use the sc lock command:

sc lock

sc pause

Sends a PAUSE control request to a service.

Syntax

sc [ServerNamepause [ServiceName]

Parameters

ServerName   : Specifies the name of the remote server on which the service is located. The name must use the UNC format ("\\myserver"). To run SC.exe locally, ignore this parameter.

ServiceName   : Specifies the service name returned by the getkeyname operation.

/? : Displays help at the command prompt.

Remarks

  • Use the pause operation to pause a service before shutting it down.

  • Not all services can be paused.

  • Not all services perform the same when paused. Some continue to service existing clients, but refuse to accept new clients. Others cease to service existing clients and also refuse to accept new ones.

Examples

The following example shows how you can use the sc pause command:

sc pause tapisrv

sc qc

Queries the configuration information for a service.

Syntax

sc [ServerNameqc [ServiceName] [BufferSize]

Parameters

ServerName   : Specifies the name of the remote server on which the service is located. The name must use the UNC format ("\\myserver"). To run SC.exe locally, ignore this parameter.

ServiceName   : Specifies the service name returned by the getkeyname operation.

BufferSize   : Specifies the size (in bytes) of the buffer. The default is 1024 bytes.

/? : Displays help at the command prompt.

Remarks

  • The qc operation displays the following information about a service: SERVICE_NAME (service's registry subkey name), TYPE, ERROR_CONTROL, BINARY_PATH_NAME, LOAD_ORDER_GROUP, TAG, DISPLAY_NAME, DEPENDENCIES, and SERVICE_START_NAME.

  • Administrators can use SC to determine the binary name of any service and find out if it shares a process with other services by typing the following at the command line:

    sc qc ServiceName

    SC can help match up services in the Services node of Microsoft Management Console (MMC) with processes in System Monitor. If the binary name is Services.exe, then the service shares the Service Controller process.

    Services.exe starts all services. To conserve system resources, several Win32 services developed for Windows are written to share the Services.exe process. These services are not listed as separate processes in System Monitor or Task Manager. The same is true of Svchost.exe which is a service host process that many operating services share.

    There might not be a process for every Win32 service because third-party Win32 services can also be configured to share processes. SC can be used to get configuration information on these services. If a service does not share its process with other services, however, there will be a process for it in System Monitor when the service is running.

  • SC can be useful for developers of services because it provides more detailed and accurate information about services than Services.exe, which is included with Windows. Services.exe can determine whether a service is running, stopped, or paused. Although these tools are adequate for a debugged application that is running smoothly, the information they provide about a service being developed can be misleading. For example, a service that is starting is shown as started whether it is actually running or not.

    SC implements calls to all Windows service control application programming interface (API) functions. Set the parameters to these functions by specifying them at the command line.

    Using SC, you can query the service status and retrieve the values stored in the status structure fields. Services.exe cannot provide you with the complete status of a service, but SC shows the exact state of the service, as well as the last checkpoint number and wait hint. You can use the checkpoint as a debugging tool because it indicates how far the initialization progressed before the program stopped responding. SC also lets you specify the name of a remote computer so that you can call the service API functions or view the service status structures on a remote computer.

Examples

The following examples show how you can use the sc qc command:

sc qc \\myserver newsrvice
sc qc rpcss 248

sc qdescription

Displays the description string of a service.

Syntax

sc [ServerNameqdescription [ServiceName] [BufferSize]

Parameters

ServerName   : Specifies the name of the remote server on which the service is located. The name must use the UNC format ("\\myserver"). To run SC.exe locally, ignore this parameter.

ServiceName   : Specifies the service name returned by the getkeyname operation.

BufferSize   : Specifies the size (in bytes) of the buffer. The default is 1024 bytes.

/? : Displays help at the command prompt.

Examples

The following examples show how you can use the sc qdescription command:

sc qdescription rpcss
sc qdescription rpcss 138

sc qfailure

Displays the actions that will be performed if the specified service fails.

Syntax

sc [ServerNameqfailure [ServiceName] [BufferSize]

Parameters

ServerName   : Specifies the name of the remote server on which the service is located. The name must use the UNC format ("\\myserver"). To run SC.exe locally, ignore this parameter.

ServiceName   : Specifies the service name returned by the getkeyname peration.

BufferSize   : Specifies the size (in bytes) of the buffer. The default is 1024 bytes.

/? : Displays help at the command prompt.

Remarks

  • The qfailure operation displays the following information about a service: SERVICE_NAME (service's registry subkey name), RESET_PERIOD, REBOOT_MESSAGE, COMMAND_LINE, and FAILURE_ACTIONS.

Examples

The following examples show how you can use the sc qfailure command:

sc qfailure rpcss
sc qfailure rpcss 20

sc query

Obtains and displays information about the specified service, driver, type of service, or type of driver.

Syntax

sc [ServerNamequery [ServiceName] [type= {driver|service|all}] [type= {own|share|interact|kernel|filesys|rec|adapt}] [state= {active|inactive|all}] [bufsize= BufferSize] [ri= ResumeIndex] [group= GroupName

Parameters

ServerName   : Specifies the name of the remote server on which the service is located. The name must use the UNC format ("\\myserver"). To run SC.exe locally, ignore this parameter.

ServiceName   : Specifies the service name returned by the getkeyname operation. This query parameter is not used in conjunction with other query parameters (other than ServerName).

type= { driver | service | all }   : Specifies what to enumerate. The default type is service.

Value

Description

driver

Specifies that only drivers are enumerated.

service

Specifies that only services are enumerated.

all

Specifies that both drivers and services are enumerated.

type= { own | share | interact | kernel | filesys | rec | adapt }   : Specifies the type of services or type of drivers to enumerate.

Value

Description

own

The service runs in its own process. It does not share an executable file with other services. This is the default.

share

The service runs as a shared process. It shares an executable file with other services.

interact

The service can interact with the desktop, receiving input from users. Interactive services must be run under the LocalSystem account.

kernel

Driver.

filesys

File system driver.

state= { active | inactive | all }   : Specifies the started state of the service for which to enumerate. The default state is active.

Value

Description

active

Specifies all active services.

inactive

Specifies all paused or stopped services.

all

Specifies all services.

bufsize=   BufferSize   : Specifies the size (in bytes) of the enumeration buffer. The default size is 1024 bytes. Increase the size of the enumeration buffer when the display resulting from a query exceeds 1024 bytes.

ri=   ResumeIndex   : Specifies the index number at which to begin or resume the enumeration. The default is 0. Use this parameter in conjunction with the bufsize= parameter when more information is returned by a query than the default buffer can display.

group=   GroupName   : Specifies the service group to enumerate. The default is all groups.

/? : Displays help at the command prompt.

Remarks

  • Without a space between a parameter and its value (that is, type= own, not type=own), the operation will fail.

  • The query operation displays the following information about a service: SERVICE_NAME (service's registry subkey name), TYPE, STATE (as well as states which are not available), WIN32_EXIT_B, SERVICE_EXIT_B, CHECKPOINT, and WAIT_HINT.

  • The type= parameter can be used twice in some cases. The first appearance of the type= parameter specifies whether to query services, drivers, or all. The second appearance of the type= parameter specifies a type from the create operation to further narrow a query's scope.

  • When the display resulting from a query command exceeds the size of the enumeration buffer, a message similar to the following is displayed:

    Enum: more data, need 1822 bytes start resume at index 79

    To display the remaining query information, rerun query, setting bufsize= to be the number of bytes and ri= to the specified index. For example, the remaining output would be displayed by typing the following at the command line:

    sc query bufsize= 1822 ri= 79

Examples

The following examples show how you can use the sc query command:

sc query
sc query messenger
sc query type= driver
sc query type= service
sc query state= all
sc query bufsize= 50
sc query ri= 14
sc query type= service type= interact
sc query type= driver group= ndis

sc queryex

Obtains and displays extended information about the specified service, driver, type of service, or type of driver.

Syntax

sc [ServerNamequeryex [type= {driver|service|all}] [type= {own|share|interact|kernel|filesys|rec|adapt}] [state= {active|inactive|all}] [bufsize= BufferSize] [ri= ResumeIndex] [group= GroupName]

Parameters

ServerName   : Specifies the name of the remote server on which the service is located. The name must use the UNC format ("\\myserver"). To run SC.exe locally, ignore this parameter.

ServiceName   : Specifies the service name returned by the getkeyname operation. This queryex parameter is not used in conjunction with any other queryex parameters except ServerName.

type= { driver | service | all }   : Specifies what to enumerate. The default type is service.

Value

Description

driver

Specifies that only drivers are enumerated.

service

Specifies that only services are enumerated.

all

Specifies that both drivers and services are enumerated.

type= { own | share | interact | kernel | filesys | rec | adapt } : Specifies the type of services or type of drivers to enumerate.

Value

Description

own

The service runs in its own process. It does not share an executable file with other services. This is the default.

share

The service runs as a shared process. It shares an executable file with other services.

interact

The service can interact with the desktop, receiving input from users. Interactive services must be run under the LocalSystem account.

kernel

Driver.

filesys

File system driver.

state= { active | inactive | all }   : Specifies the started state of the service for which to enumerate. The default state is active.

Value

Description

active

Specifies all active services.

inactive

Specifies all paused or stopped services.

all

Specifies all services.

bufsize=   BufferSize   : Specifies the size (in bytes) of the enumeration buffer. The default size is 1024 bytes.

ri=   ResumeIndex   : Specifies the index number at which to begin or resume the enumeration. The default is 0.

group=   GroupName   : Specifies the service group to enumerate. The default is all groups.

/? : Displays help at the command prompt.

Remarks

  • Without a space between a parameter and its value (that is, type= own, not type=own), the operation will fail.

  • The queryex operation displays the following information about a service: SERVICE_NAME (service's registry subkey name), TYPE, STATE (as well as states that are not available), WIN32_EXIT_B, SERVICE_EXIT_B, CHECKPOINT, WAIT_HINT, PID, and FLAGS.

  • The type= parameter can be used twice in some cases. The first appearance of the type= parameter specifies whether to query services, drivers, or all. The second appearance of the type= parameter specifies a type from the create operation to further narrow a query's scope.

  • When the display resulting from a queryex command exceeds the size of the enumeration buffer, a message similar to the following is displayed:

    Enum: more data, need 2130 bytes start resume at index 75

    To display the remaining queryex information, rerun queryex, setting bufsize= to be the number of bytes and ri= to the specified index. For example, the remaining output would be displayed by typing the following at the command line:

    sc queryex bufsize= 2130 ri= 75

Examples

The following examples show how you can use the sc queryex command:

sc queryex messenger
sc queryex group= ""

sc querylock

Queries and displays the lock status for the Service Control Manager's database.

Syntax

sc [ServerNamequerylock

Parameter

ServerName   : Specifies the name of the remote server on which the service is located. The name must use the UNC format ("\\myserver"). To run SC.exe locally, ignore this parameter.

/? : Displays help at the command prompt.

sc sdset

Sets a service's security descriptor using Service Descriptor Definition Language (SDDL).

Syntax

sc [ServerNamesdset ServiceName ServiceSecurityDescriptor

Parameters

ServerName   : Specifies the name of the remote server on which the service is located. The name must use the UNC format ("\\myserver"). To run SC.exe locally, ignore this parameter.

ServiceName   : Specifies the service name returned by the getkeyname operation.

ServiceSecurityDescriptor   : Specifies the service descriptor in SDDL.

/? : Displays help at the command prompt.

Remarks

  • For more information about SDDL, see "Security Descriptor Definition Language" at the MSDN Online Library.

sc sdshow

Displays a service's security descriptor using SDDL.

Syntax

sc [ServerNamesdshow ServiceName

Parameters

ServerName   : Specifies the name of the remote server on which the service is located. The name must use the UNC format ("\\myserver"). To run SC.exe locally, ignore this parameter.

ServiceName   : Specifies the service name returned by the getkeyname operation.

/? : Displays help at the command prompt.

Remarks

  • For more information about SDDL, see "Security Descriptor Definition Language" at the MSDN Online Library.

Examples

sc sdshow rpcss

sc start

Starts a service running.

Syntax

sc [ServerNamestart ServiceName [ServiceArguments]

Parameters

ServerName   : Specifies the name of the remote server on which the service is located. The name must use the UNC format ("\\myserver"). To run SC.exe locally, ignore this parameter.

ServiceName   : Specifies the service name returned by the getkeyname operation.

ServiceArguments   : Specifies service arguments to pass to the service to be started.

/? : Displays help at the command prompt.

Examples

The following example shows how you can use the sc start command:

sc start tapisrv

sc stop

Sends a STOP control request to a service.

Syntax

sc [ServerNamestop ServiceName

Parameters

ServerName   : Specifies the name of the remote server on which the service is located. The name must use the UNC format ("\\myserver"). To run SC.exe locally, ignore this parameter.

ServiceName   : Specifies the service name returned by the getkeyname operation.

/? : Displays help at the command prompt.

Remarks

  • Not all services can be stopped.

Examples

The following example shows how you can use the sc stop command:

sc stop tapisrv

Remarks

Formatting legend

Format

Meaning

Italic

Information that the user must supply

Bold

Elements that the user must type exactly as shown

Ellipsis (...)

Parameter that can be repeated several times in a command line

Between brackets ([])

Optional items

Between braces ({}); choices separated by pipe (|). Example: {even|odd}

Set of choices from which the user must choose only one

Courier font

Code or program output

Command-line reference A-Z