Platform SDK: DLLs, Processes, and Threads |
The ChangeServiceConfig function changes the configuration parameters of a service.
To change the optional configuration parameters, use the ChangeServiceConfig2 function.
BOOL ChangeServiceConfig( SC_HANDLE hService // handle to service DWORD dwServiceType, // type of service DWORD dwStartType, // when to start service DWORD dwErrorControl, // severity of start failure LPCTSTR lpBinaryPathName, // service binary file name LPCTSTR lpLoadOrderGroup, // load ordering group name LPDWORD lpdwTagId, // tag identifier LPCTSTR lpDependencies, // array of dependency names LPCTSTR lpServiceStartName, // account name LPCTSTR lpPassword, // account password LPCTSTR lpDisplayName // display name );
Type | Meaning |
---|---|
SERVICE_WIN32_OWN_PROCESS | Specifies a service that runs in its own process. |
SERVICE_WIN32_SHARE_PROCESS | Specifies a service that shares a process with other services. |
SERVICE_KERNEL_DRIVER | Specifies a driver service. |
SERVICE_FILE_SYSTEM_DRIVER | Specifies a file system driver service. |
If you specify either SERVICE_WIN32_OWN_PROCESS or SERVICE_WIN32_SHARE_PROCESS, you can also specify the following type.
Type | Meaning |
---|---|
SERVICE_INTERACTIVE_PROCESS | Enables a service to interact with the desktop. |
Type | Meaning |
---|---|
SERVICE_BOOT_START | Specifies a device driver started by the system loader. This value is valid only for driver services. |
SERVICE_SYSTEM_START | Specifies a device driver started by the IoInitSystem function. This value is valid only for driver services. |
SERVICE_AUTO_START | Specifies a service to be started automatically by the service control manager during system startup. |
SERVICE_DEMAND_START | Specifies a service to be started by the service control manager when a process calls the StartService function. |
SERVICE_DISABLED | Specifies a service that can no longer be started. |
Values | Meaning |
---|---|
SERVICE_ERROR_IGNORE | The startup program logs the error but continues the startup operation. |
SERVICE_ERROR_NORMAL | The startup program logs the error and puts up a message box pop-up but continues the startup operation. |
SERVICE_ERROR_SEVERE | The startup program logs the error. If the last-known-good configuration is being started, the startup operation continues. Otherwise, the system is restarted with the last-known-good configuration. |
SERVICE_ERROR_CRITICAL | The startup program logs the error, if possible. If the last-known-good configuration is being started, the startup operation fails. Otherwise, the system is restarted with the last-known good configuration. |
You can use a tag for ordering service startup within a load ordering group by specifying a tag order vector in the GroupOrderList value of the following registry key:
HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control
Tags are only evaluated for driver services that have SERVICE_BOOT_START or SERVICE_SYSTEM_START start types.
You must prefix group names with SC_GROUP_IDENTIFIER so that they can be distinguished from a service name, because services and service groups share the same name space.
If the service type is SERVICE_KERNEL_DRIVER or SERVICE_FILE_SYSTEM_DRIVER, the name is the driver object name that the system uses to load the device driver. Specify NULL if the driver is to use a default object name created by the I/O system.
For more information, see the warning in the Remarks section.
Passwords are ignored for driver services.
If the function succeeds, the return value is nonzero.
If the function fails, the return value is zero. To get extended error information, call GetLastError.
The following error codes may be set by the service control manager. Other error codes may be set by the registry functions that are called by the service control manager.
Error code | Meaning |
---|---|
ERROR_ACCESS_DENIED | The specified handle was not opened with SERVICE_CHANGE_CONFIG access. |
ERROR_CIRCULAR_DEPENDENCY | A circular service dependency was specified. |
ERROR_DUP_NAME | The display name already exists in the service controller manager database, either as a service name or as another display name. |
ERROR_INVALID_HANDLE | The specified handle is invalid. |
ERROR_INVALID_PARAMETER | A parameter that was specified is invalid. |
ERROR_INVALID_SERVICE_ACCOUNT | The account name does not exist, or a service is specified to share the same binary file as an already installed service but with an account name that is not the same as the installed service. |
ERROR_SERVICE_MARKED_FOR_DELETE | The service has been marked for deletion. |
The ChangeServiceConfig function changes the configuration information for the specified service in the service control manager database. You can obtain the current configuration information by using the QueryServiceConfig function.
If the configuration is changed for a service that is running, with the exception of lpDisplayName, the changes do not take effect until the service is stopped.
The startup program uses load ordering groups to load groups of services in a specified order with respect to the other groups in the list. The list of load ordering groups is contained in the ServiceGroupOrder value of the following registry key:
HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control
Warning Setting the lpServiceStartName parameter changes the logon account of the service. This can cause problems. If you have registered a service principal name (SPN), it would now be registered on the wrong account. Similarly, if you have used an ACE to grant access to a service, it would now grant access to the wrong account.
Windows NT/2000: Requires Windows NT 3.1 or later.
Header: Declared in Winsvc.h; include Windows.h.
Library: Use Advapi32.lib.
Unicode: Implemented as Unicode and ANSI versions on Windows NT/2000.
Services Overview, Service Functions, ChangeServiceConfig2, CreateService, OpenService, QueryServiceConfig, QueryServiceConfig2, StartService