ServiceAddService

InstallShield 2018 » InstallScript Language Reference

The ServiceAddService function adds the service specified by szServiceName to the list of services registered on the system. You can customize the SERVICE_IS_PARAMS structure to control additional service creation elements. ServiceAddService does not install any files; you must install the service file yourself during the installation.

If the service specified by szServiceName already exists, ServiceAddService reconfigures it to the parameters specified in the function call. If the existing service is running when ServiceAddService is called, the installation attempts to stop the service before attempting to reconfigure the service. If the service cannot be stopped, ServiceAddService reconfigures the service and sets BATCH_INSTALL to non-zero so that Windows can complete the service reconfiguration after reboot.

Syntax

ServiceAddService ( szServiceName, szServiceDisplayName, szServiceDescription, szServicePathFile, bStartService, szStartServiceArgs );

Parameters

ServiceAddService Parameters

Parameter

Description

szServiceName

Specifies the name of the service.

szServiceDisplayName

Specifies the display name of the service.

szServiceDescription

Specifies the service description.

szServicePathFile

Specifies the path to the service executable file and, optionally, command line parameters that are passed to the service whenever it is started.

bStartService

Specifies whether to start the service after adding it.

szStartServiceArgs

Specifies command line arguments that are passed to the service only when it is started by the installation.

Return Values

ServiceAddService Return Values

Return Value

Description

>= ISERR_SUCCESS

Indicates that the function successfully added or reconfigured the service.

< ISERR_SUCCESS

Indicates that the function was unable to add or reconfigure the service.

If this function fails, additional error information may be available by calling GetExtendedErrInfo and checking the value of its third argument. (This value typically indicates the result of internally calling the Windows API function GetLastError after a call to a Windows API function failed.)

You can obtain the error message text associated with a large negative return value—for example, -2147024891 (0x80070005)—by calling FormatMessage.

Additional Information

If logging is enabled when ServiceAddService is called, the service is logged for uninstallation whether or not the service existed already and is removed when the application is uninstalled. If you are adding a service that should not be uninstalled, disable logging before calling this function.

Note that the publicly defined structures—SERVICE_IS_PARAMS and SERVICE_IS_STATUS—are not used when the service is uninstalled automatically. If you want to specify non-default settings when uninstalling the service, disable logging when adding the service and then remove the service manually during uninstallation by calling ServiceRemoveService directly from the script.

See Also