SC command to create and remove Windows services

Source: Internet
Author: User

Command format:

SC [servername] Create Servicename [optionname= optionvalues]

ServerName

Optionally, you can use a double slash, such as \\\\myserver, or \\\\192.168.0.1 to manipulate the remote computer. If you are working on your local computer, you do not have to add any parameters.

Servicename

The name that is established for service key in the registry. Note that this name is different from the display name (this name can be seen with the net start and the Service Control Panel), and the SC uses the service key name to authenticate the service.

Optionname

This optionname and optionvalues parameter allows you to specify the name and value of the action command parameter. Note that it is important that there are no spaces between the action name and the equals sign.

If you want to see the available optionvalues for each command, you can use the SC command in this format. This will provide you with detailed help.

Optionvalues

Specify a value for the name of the Optionname parameter. The range of valid values is often limited to the optionname of which parameter. If you want to list please use SC command to ask for each command.

Optionname--optionvalues description

type=----own, share, interact, kernel, Filesys

For the type of service being established, the option value includes the type used by the driver, which is share by default.

start=----boot, sys tem, auto, demand, disabled

For the type of startup service, the option value includes the type used by the driver, which by default is demand (manual).

error=----Normal, severe, critical, ignore

When the service fails to import the severity of the error, the default is normal.

binpath=--(String)

The pathname of the service binaries, where there are no default values, this string must be set.

group=----(String)

The group that this service belongs to, and the list of this group is saved under ServiceGroupOrder in the registry. The default is nothing.

tag=----(String)

If the string is set to YES,SC, a tagid can be obtained from CreateService call. However, SC does not display this label, so using this does not make much sense. Default is Nothing

depend=----(space separated string) with a space.

The name or group of the service that must be started before this service is started.

obj=----(String)

The name used to run the account is also the login status. The default is Localsys tem

displayname=--(String)

A string that is used to authenticate individual services in a user-interface program.

password=--(String)

A password that needs to be used if a different account is used than the Localsys tem.

Optionvalues

A list of values for the Optionname parameter name. Refer to Optionname. When we enter a string, if you enter an empty reference, this means that an empty string will be imported.

It is important to note that:

1. In the option= xxxxx format, the "=" number and the following must have spaces, such as depend= Tcpip

2. If the command needs to be nested in double quotes, use the backslash quotation mark "\" to escape processing.

Example

"\" D:\Servers\Subversion\bin\svnserve.exe\ "--service-r E:\SVN\repository"svnservice   
To Remove a Windows service by using the SC command

SC Delete

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

Grammar

Parameters

ServerName

Specifies the name of the remote server where the service resides. The name must use the UNC format ("\\MyServer"). To run SC.exe on this computer, ignore this parameter.

ServiceName

Specifies the name of the service returned by the getkeyname operation.

Example

SC Delete Svnservice
failure prompt:deleteservice FAILED 1072

When you delete a service, you may encounter a failure prompt "DeleteService FAILED 1072:the specified service has been marked for deletion.", or run without error, but the service is still in the service management list.

This is because when the server is unloaded, it checks the status (actually the state of the tag, checks when the service is started, determines whether to start or unload). If it is in a startup state, it is unloaded automatically when the service is stopped, or unloaded immediately. So the cause of the error may be because the service is in the boot state, so cannot be deleted, if you need to delete immediately, you need to use the command to terminate the service, the command format is as follows:

sc stop ServiceName

SC command to create and remove Windows services

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.