Windows SC (Server Control) commands

Source: Internet
Author: User

As a command tool,SC .exe

Yes
To test your own system, you can set a batch file to use different parameters to call
SC .exe to control the service. This is useful. If you want to see how your service is continuously started and stopped, I have not tried it! It sounds good to let a service open and close at once. If you
If there are multiple processes in the service process, you can keep a process running without letting it go, and then let another process continuously open and close, you can also find evidence that the memory is not completely clear.

The following describes SC, SC qc, and SC query.

SC uses the following syntax:

1. SC [servername] command servicename [optionname = optionvalues]

2. SC [command]

The first syntax uses SC and the second syntax displays help.

The following describes the parameters.

Servername

Optional: You can use double slashes, such as myserver or 192.168.0.1 to operate remote computers. If you operate on a local computer

You do not need to add any parameters.

Command

The following lists the SC commands that can be used.

Config ---- change the configuration of a service. (Long term)

Continue -- send a request for continuous control to a service.

Control ---- send a control to a service.

Create ---- create a service. (Add to Registry)

Delete ---- delete a service. (Delete from Registry)

Enumdepend -- lists the service subordination.

Getdisplayname -- get the display name of a service.

Getkeyname -- get the service key name of a service.

Interrogate -- sends a query control request to a service.

Pause ---- send a suspend control request to a service.

QC ---- ask about the configuration of a service.

Query ---- query the status of a service. You can also list the status types of the service.

Start ---- start a service.

Stop ---- requests a service to send a stop request.

Servicename

Name specified for the service key in the registry. Note that this name is different from the display name (this name can be seen in Net start and Service Control Panel), and SC uses the service key name to identify the service.

Optionname

The optionname and optionvalues parameters allow you to specify the name and value of the operation command parameters. Note that there is no space between the operation name and the equal sign. I don't know the result at first .................., For example, start = optionvalues, which is very important.

Optionvalues can be 0, 1, or more operation parameter names and value pairs.

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

Optionvalues

Specify a value for the parameter name of optionname. The range of valid values is usually limited to the optionname parameter. Use

SC command to query each command.

Comments

Many Commands require administrator permissions, so I would like to say that you should be the administrator when operating these commands. Haha!

When you click "SC .exe" without any commands, SC .exe displays help information and available commands. When you type SC followed by the command name, you can get a detailed list of the commands. For example, you can enter SC create to obtain a list related to create.

Except for one command, SC query exports the status of all services and drivers currently running in the system.

When you use the start command, you can pass some parameters (arguments) to the main function of the service, but not to the main function of the service process.

SC create

This command can be used to create an entry in the Registry and service control management database.

Syntax 1

SC [servername] Create servicename [optionname = optionvalues]

The servername, servicename, optionname, and optionvalues here are the same as those above. Here we will describe optionname and optionvalues in detail.

Optionname -- optionvalues

Description

Type = ---- own, share, interact, kernel, filesys

About the service creation type, the option value includes the type used by the driver. The default value is share.

Start = ---- boot, sys tem, auto, demand, Disabled

About the Service Startup type, the option value includes the type used by the driver. The default value is demand (Manual ).

Error = ---- normal, severe, critical, ignore

The default value is normal.

Binpath = -- (string)

The path name of the Service binary file. There is no default value here. This string must be set.

Group = ---- (string)

The group to which this service belongs. The list of this group is saved under servicegrouporder in the registry. The default value is nothing.

Tag = ---- (string)

If this string is set to yes, SC can get a tagid from createservice call. However, SC does not display this label, so it makes little sense to use this label. The default value is nothing.

Depend = ---- (space separated string) string with spaces.

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

OBJ = ---- (string)

The name used for account running. The default value is localsys TEM.

Displayname = -- (string)

A string used to identify each service in the user interface program.

Password = -- (string)

A password, which must be used if it is used by a different account than localsys TEM.

Optionvalues

The Value List of the optionname parameter. Refer to optionname. When we input a string, If we input an empty reference, this means

An empty string will be imported.

Comments

The SC CREATE Command performs the operations of the createservice API function.

Run the SC CREATE command to execute the createservice API function. For details, see createservice.

Example 1

The following example shows how to register a registry created for a service called newservice on a computer called myserver.

SC myserver create newservice binpath = C: winntsys tem32newserv.exe

By default, this service creates a win32_assist_process startup mode using service_demand_start. This will not have any subordination, but will also run according to the localsys TEM Security upper-lower relationship.

Example 2

In the following example, a service is created on a local computer and runs on its own process automatically. It belongs to the TDI group and NetBIOS service. Note that you must add a space reference to the slave.

SC create newservice binpath = C: winntsys tem32newserv.exe type = own

Start = auto depend = '+ TDI NetBIOS'

Example 3

Service developers can temporarily change the binary path (image path) to run the service in the context of the kernel debugger. The following example shows how to change the service configuration.

SC config newservice binpath = 'ntsd-D C: winntsys tem32newserv.exe'

In this example, the service controller calls ntsd.exe to use the following parameter string:

'-D c: tsys tem32newserv.exe'

When the system is installed with newserv.exe, ntsd will interrupt the debugger, so the breakpoint can be set in the service code.

SC QC

This SC QC "query configuration" command can list the configuration information of a service and the query_service_config structure.

Syntax 1

SC [servername] QC servicename [buffersize]

Parameters

Servername and servicename have already been introduced.

Buffersize, which can be used to list the buffer size.

Comments

The SC QC command displays the content of the query_service_config structure.

The following is the region of query_service_config.

Type ------ dwservicetype

Start_type ---- dwstarttype

Error_control ---- dwerrorcontrol

Binary_path_name -- lpbinarypathname

Load_order_group -- lploadordergroup

Tag ------ dwtagid

Display_name ---- lpdisplayname

Dependencies ---- lpdependencies

Service_start_name -- lpservicestartname

Example 1

The following example shows the configuration of the "newservice" service created in the preceding example:

SC myserver QC newservice

SC displays the following information:

SERVICE_NAME: newservice

Type: 20 win32_0000_process

Start_type: 3 demand_start

Error_control: 1 normal

Binary_path_name: C: winntsys tem32newserv.exe

Load_order_group:

Tag: 0

Display_name: newservice

Dependencies:

Service_start_name: localsys TEM

Newservice can share a process with other services. But it is not automatically started. The binary file name is newserv.exe. This service does not depend on other services,
And run in lcoalsys
The security context of TEM. These are basic responses to queryservicestatus. If you need more details, you can check the API function file.

SC Query

The SC query command can obtain service information.

Syntax:

SC [servername] query {servicename | optionname = optionvalues ...}

Parameters:

Servername, servicename, optionname, and optionvalues are not interpreted. Let's just talk about the value provided by this command.

Optionname -- optionvalues

Description

Type = ---- driver, service, all

Lists the service types. The default value is service.

State = ---- active, inactive, all

Lists the status of a Service. The default value is active.

Bufsize = -- (numeric values)

List the buffer size. The default value is 1024 bytes.

Ri = ---- (numeric values)

However, when listing, the number of the Restoration pointer is 0 by default.

Optionvalues

Same as above.

Comments

The SC query command displays the service_status structure.

The following figure shows the service_status structure:

Type ------ dwservicetype

State ------ dwcurrentstate, dwcontrolsaccepted

Win32_exit_code ---- dwwin32exitcode

Service_exit_code -- dwservicespecificexitcode

Checkpoint ---- dwcheckpoint

Wait_hint ---- dwwaithint

After the computer is started, the SC query command will tell you whether or not to start the service. If the service is successfully started, the win32_exit_code interval will contain a value of 0. When the attempt fails, it realizes that the service cannot be started, this interval also provides an exit code for the service.

Example

To query the service status of newservice, type:

SC query newservice

The following information is displayed:

SERVICE_NAME: newservice

Type: 20 win32_0000_process

State: 1 stopped

(Not_stoppable, not_pausable, ignores_shutdown)

Win32_exit_code: 1077 (0x435)

Service_exit_code: 0 (0x0)

Checkpoint: 0x0

Wait_hint: 0x0

Note: there is an exit code for this service. Even if this service department is not running, type net helpmsg 1077 and you will get a description of the error 1077:

The service has not been started yet.

So here I want to say that we hope you can use net helpmsg, which will be of great help to your learning.

The following describes the SC query command:

To list the status of the active service and driver, run the following command:

SC Query

To display the messenger service, run the following command:

SC query messenger

To list only the active drivers, run the following command:

SC Query type = driver

To list Win32 services, run the following command:

SC Query type = Service

To list all services and drivers, run the following command:

SC query state = all

Use a buffer of 50 bytes to list data. Use the following command:

SC query bufsize = 50

Use Index = 14 to restore the list. Run the following command:

SC query rI = 14

To list all interactive services, run the following command:

SC Query type = service type = interact

Now, let's talk about it. The SC command is basically finished. Hope you can take a good look! I believe it will help !!

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.