Service Configuration Programs
Programmers and system administrators use service configuration programs to modify or query the database of installed services. The database can also be accessed by using the registry functions. However, you should only use the SCM configuration functions, which ensure that the service is properly installed and configured. The SCM configuration functions require either a handle to an SCManager object or a handle to a service object. To obtain these handles, the service configuration program must:
Service Installation, Removal, and Enumeration
A configuration program uses the CreateService() function to install a new service in the SCM database. This function specifies the name of the service and provides configuration information that is stored in the database. A configuration program uses the DeleteService() function to remove an installed service from the database. To obtain the service name, call the GetServiceKeyName() function. The service display name, used in the Services control panel applet, can be obtained by calling the GetServiceDisplayName() function. A service configuration program can use the EnumServicesStatusEx() function to enumerate all services and their statuses. It can also use the EnumDependentServices() function to enumerate which services are dependent on a specified service object.
The system uses the configuration information to determine how to start the service. The configuration information also includes the service display name and its description. For example, for the DHCP service, you could use the display name Dynamic Host Configuration Protocol Service and the description Provides internet addresses for computer on your network. To modify the configuration information for a service object, a configuration program uses the ChangeServiceConfig() or ChangeServiceConfig2() function. To retrieve the configuration information for a service object, the configuration program uses the QueryServiceConfig() or QueryServiceConfig2() function. To modify the security descriptor for either an SCManager object or a service object, a configuration program uses the SetServiceObjectSecurity() function. To retrieve a copy of the security descriptor, the configuration program uses the QueryServiceObjectSecurity() function.
Configuring a Service Using SC
The Windows SDK contains a command-line utility, Sc.exe, that can be used to query or modify the database of installed services. Its commands correspond to the functions provided by the SCM. The syntax is as follows.
Syntax: sc [ServerName] Command [ServiceName][option1][option2]...
ServerName: Optional server name. Use the form \\ServerName.
Command: One of the following commands:
ServiceName: The name of the service, as specified when it was installed.
option1: An optional parameter.
option2: An optional parameter.
To see complete syntax for a command, use the following command: