installshield installscript, need code to install and start a windows service

bluedragon99 used Ask the Experts™
Need installscript code to install and start a service at the end of my installation..

Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

There are several wrapper dll's available for doing this....

However if you are using Installshield 2009 (and probably many of the earlier versions as well) you should check out this method below.
InstallShield 2009 » 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. This function is supported only for Windows NT, Windows 2000, and Windows XP systems; the function will fail on Windows 95, Windows 98, and Windows Me systems. 
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. 
ServiceAddService ( szServiceName, szServiceDisplayName, szServiceDescription, szServicePathFile, bStartService, szStartServiceArgs ); 
ServiceAddService Parameters  
 Specifies the name of the service. 
 Specifies the display name of the service. 
 Specifies the service description. (The service description is relevant only on Windows 2000 and later.) 
 Specifies the path to the service executable file and, optionally, command line parameters that are passed to the service whenever it is started. 
 Specifies whether to start the service after adding it. 
 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 
 Indicates that the function successfully added or reconfigured the service. 
 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 valuefor 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 structuresSERVICE_IS_PARAMS and SERVICE_IS_STATUSare 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. 

Open in new window

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial