ChangeServiceConfig

  BOOL ChangeServiceConfig(hService, dwServiceType, dwStartType, dwErrorControl, lpBinaryPathName, lpLoadOrderGroup, lpDependencies, lpServiceStartName, lpPassword)    
  SC_HANDLE hService;    
  DWORD dwServiceType;    
  DWORD dwStartType;    
  DWORD dwErrorControl;    
  LPTSTR lpBinaryPathName;    
  LPTSTR lpLoadOrderGroup;    
  LPTSTR lpDependencies;    
  LPTSTR lpServiceStartName;    
  LPTSTR lpPassword;    

The ChangeServiceConfig function changes the service configuration parameters.

Parameters

hService

Handle obtained from a previous OpenService call.

dwServiceType

Value to indicate the type of service this is.

Value Meaning

SERVICE_WIN32_OWN_PROCESS a service which runs in its own Win32 process.
SERVICE_WIN32_SHARE_PROCESS a service which shares a Win32 process with other services.
SERVICE_DRIVER an NT device driver.
SERVICE_NO_CHANGE do not modify existing ServiceType value.

dwStartType

Value to specify when to start the service.

Value Meaning

SERVICE_BOOT_START Only valid if service type is SERVICE_DRIVER. This device driver is to be started by the OS loader.
SERVICE_SYSTEM_START Only valid if service type is SERVICE_DRIVER. This device driver is to be started by IoInitSystem.
SERVICE_AUTO_START Valid for both SERVICE_DRIVER and SERVICE_WIN32 service types. This service is started by the Service Control Manager automatically during boot.
SERVICE_DEMAND_START Valid for both SERVICE_DRIVER and SERVICE_WIN32 service types. This service is started by the Service Control Manager when a start request is issued via the StartService API.
SERVICE_DISABLED This service can no longer be started.
SERVICE_NO_CHANGE do not modify existing StartType value.

dwErrorControl

Value to specify the severity of the error if this service fails to start during boot so that the appropriate action can be taken.

Value Meaning

SERVICE_ERROR_NORMAL Log error but system continues to boot.
SERVICE_ERROR_SEVERE Log error, and the system is rebooted with the last-known-good configuration. If the current configuration is last-known-good, press on with boot.
SERVICE_ERROR_CRITICAL Log error if possible, and system is rebooted with last-known-good configuration. If the current configuration is last-known-good, boot fails.
SERVICE_NO_CHANGE do not modify existing StartType value.

lpBinaryPathName

Fully-qualified path name to the service binary file.

lpLoadOrderGroup

Name of the load ordering group which this service is a member of. Groups of services are started based on the group order list specified in the registry at HKEY_LOCAL_MACHINE\System\ CurrentControlSet\Control\Service_Group_Order (see Boot Configuration Specification for details). The group order takes precedence over the service start dependencies specified in the lpDependencies parameter.

lpDependencies

Space-separated names of services which must be running before this service can run. An empty string means that this service has no dependencies.

lpServiceStartName

If service type is SERVICE_WIN32, this name is the account name in the form of “DomainName\Username” which the service process will be logged on as when it runs. If the account belongs to the built-in domain, “.\Username” can be specified. If service type is SERVICE_DRIVER, this name must be the NT driver object name (e.g. \FileSystem\LanManRedirector or\Driver\Xns) which the I/O system uses to load the device driver.

lpPassword

Password to the account name specified by lpServiceStartName if service type is SERVICE_WIN32. This password will be changed periodically by the Service Control Manager so that it will not expire. If service type is SERVICE_DRIVER, this parameter is ignored.

Return Value

Returns TRUE if the specified service configuration information is successfully changed in the Service Control Manager database. If the return value is FALSE, an error has occurred. Use GetLastError to determine the cause of the failure.

Errors Value Meaning
  ERROR_ACCESS_DENIED The specified handle was not opened with SERVICE_CHANGE_CONFIG access.
  ERROR_INVALID_HANDLE The specified handle is invalid.
  ERROR_INVALID_SERVICE_ACCOUNT The account name does not exist, or the service is specified to share the same binary file as an already installed service but has an account name that is not the same as the installed service.
  ERROR_INVALID_PARAMETER A parameter specified is invalid.

Comments

This function changes the service configuration information kept in the Service Control Manager database. This configuration information was first set in the database via the CreateService API, and can be queried (except for the password parameter) using the QueryServiceConfig API.

All configuration parameters specified to this function are optional. A string parameter is not changed if it is set to NULL. A DWORD parameter is not changed if SERVICE_NO_CHANGE is specified.