Windows 2003 Server has a SC command (it seems that Windows 2000/XP/NT has this command .) This command can be used to manually create a Windows Service (NT Service)
The following describes the SC command in the Microsoft Help file:
Communicate with the service controller and installed devices. SC .exe retrieves and sets service control information. You can use SC .exe to test and debug the service.Program. You can set service properties stored in the registry to control how to start the service application at startup and when running as the background program. The SC .exe parameter can be used to configure the specified service, retrieve the current service status, or stop and start the service. You can generate a batch file to call different SC .exe commands to automatically start or close the service sequence. SC .exe provides functions similar to "services" in "Administrative Tools" in "Control Panel ".
Other command options can be checked for help by yourself, mainly look at the two commonly used commands "CREATE" and "delete"
SC create
Create a subitem and entry for the service in the Registry and Service Control Manager.
Syntax
SC[Servername]Create[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
-
-
The name of the remote server where the service is located. The name must be in UNC format ("\ myserver "). To run SC .exe on the local machine, ignore this parameter.
-
-
Servicename
-
-
Specify
GetkeynameService name returned by the operation.
-
-
Type ={
Own|
Share|
Kernel|
Filesys|
REC|
Adapt|
Interact
Type ={
Own|
Share}}
-
-
Specify the service type. The default type is
Type = own.
Value
Description
Own
Services run with their own processes. Do not share executable files with other services. This is the default setting.
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 recognition drive (identify the file system used on the computer ).
Interact
The service can interact with the desktop to receive user input. Interactive services must run under the LocalSystem account. This type must beType = ownOrType = shared(For example,Type = interact type = own. Separate useType = interactAn invalid parameter error occurs.
-
-
Start ={
Boot|
System|
Auto|
Demand|
Disabled}
-
-
Specify the Service Startup type. The default start type is
Start = demand.
Boot
The device drive loaded by the boot loader.
System
The device drive that is started during core initialization.
Auto
The service can be started automatically every time the computer is restarted and no one is logged on to the computer.
Demand
Services that must be manually started. If noStart =, Which is the default value.
Disabled
The service cannot be started. To start a disabled service, change the Startup type to another value.
-
-
Error ={
Normal|
Severe|
Critical|
Ignore}
-
-
If the server fails to be started, the error severity is specified. The default value is
ASCII.
Normal
An error is recorded and a message dialog box is displayed to notify the user that the service fails to be started. Start will continue. This is the default setting.
Severe
Record errors (if any ). The computer tries to restart with the latest valid configuration. This may cause the computer to restart, but the server still cannot run.
Critical
Record errors (if any ). The computer tries to restart with the latest valid configuration. If the correct configuration failed last time, the startup will also fail, and the startup process will stop with a "blue screen" error.
Ignore
The error has been recorded. Start and continue. The recorded error is out of the range of the event log and is no longer prompted to the user.
-
-
Binpath =
Binarypathname
-
-
Specifies the path to the service binary file.
Binpath =No default value. This string must be provided.
-
-
Group =
Loadordergroup
-
-
Specify a group name in which the service is a member. The group list is stored in the registry of the subitem HKLM \ System \ CurrentControlSet \ Control \ servicegrouporder. The default value is null.
-
-
Tag ={
Yes|
No}
-
-
Whether to obtain the tagid in the createservice call. Flag is only used for root start or system start driver.
-
-
Depend =
Dependencies
-
-
Specify the service name or group name that must be started before this service. The name is separated by a slash.
-
-
OBJ ={
Accountname|
Objectname}
-
-
Specify the account name of the service to be run, or specify the Windows Driver Object Name of the driver to be run.
-
-
Displayname =
Displayname
-
-
Specifies the friendly name used by the user interface program to identify the service.
-
-
Password:
Password
-
-
Specify a password. If you are not using a LocalSystem account, the password is required.
-
-
/?
-
-
Display help at a command prompt.
Note
- If there is no space between the parameter and its value (for example, yesType = ownInsteadType = own), The Operation will fail.
Example
The following example shows how to useSC createCommand:
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
Delete A service subitem from the registry. If the service is running or another process has an open handle for the service, the service is marked as deleted.
Syntax
SC[Servername]Delete[Servicename]
Parameters
-
Servername
-
The name of the remote server where the service is located. The name must be in UNC format ("\ myserver "). To run SC .exe on the local machine, ignore this parameter.
-
Servicename
-
Specify
GetkeynameService name returned by the operation.
-
/?
-
Display help at a command prompt.
Note
- Use add or remove programs to delete DHCP, DNS, or any other built-in operating system services. "Add or delete programs" not only deletes the registry subkeys of the service, but also uninstalls the service and deletes all its shortcuts.
Example
The following example shows how to useSC DeleteCommand:
SC Delete newserv
Note that:
1. In option = XXXXX format, there must be spaces between "=" and the following content, such as depend = TCPIP
2. If the double quotation marks need to be nested in the command, use the backslash plus the quotation marks "\" to escape.