Summary
This article explains how to properly start/stop an NT Service in the correct amount of time using InstallScript in InstallShield 10.5 and 11 and gives you background information on how the ServiceStopService() and ServiceStartService() functions currently work, explaining why it takes the script engine the time it does and why you need to implement the following logic to properly start/stop an NT Service.Synopsis
This article explains how to properly start/stop an NT Service in the correct amount of time using InstallScript in InstallShield 10.5 and 11.
This article also gives you background information on how the ServiceStopService() and ServiceStartService() functions currently work, explaining why it takes the script engine the time it does and why you need to implement the following logic to properly start/stop an NT Service.
Discussion
If you rely just on the ServiceStopService() and ServiceStartService() functions to start/stop an NT Service, you may experience a long delay before the NT Service is actually started/stopped. In short, this is due to the functions waiting on the dwWaitHint parameter set by the NT Service and is further explained in the Additional Information section.
Future releases of InstallShield will allow you to override the dwWaitHint parameter set by an NT Service in InstallScript, but for now if you are using InstallShield 10.5 or 11, you will have to implement the following to properly start/stop your NT Service.
- Set the nStartServiceWaitCount/nStopServiceWaitCount to 0. This causes the functions to bypass any wait, including the wait specified by the dwWaitHint parameter.
- Call the appropriate ServiceStopService() or ServiceStartService() function to perform the action required.
- Use the ServiceGetServiceState() function to check the state of the NT Service in question in a while loop. You can also use the Delay() function while you wait until the NT Service has fully started or stopped. See the Help Library for more information on either the ServiceGetServiceState() or Delay() functions.
By adding the preceding logic into your code, you will be able to properly start/stop an NT Service in the correct amount of time.
Additional Information
Internally, the ServiceStopService() and ServiceStartService() functions perform the following in InstallShield 10.5 and 11:
- Check the state of the service, if it matches SERVICE_RUNNING/SERVICE_STOPPED (respectively), the function returns success.
- Check whether SERVICE_IS_PARAMS.nStartServiceWaitCount or SERVICE_IS_PARAMS.nStopServiceWaitCount has passed, if so, the functions checks the service?s status, if it does not match SERVICE_RUNNING/SERVICE_STOPPED the function returns failure.
- If the service?s state does not match SERVICE_RUNNING/SERVICE_STOPPED and the nStartServiceWaitCount/nStopServiceWaitCount has not passed, the setup then re-queries the state of the service and sleeps for the amount of time amount of time specified by the dwWaitHint set by the service.
NOTE: Once the wait specified by dwWaitHint begins, it always completes regardless of the values of nStartServiceWaitCount/nStopServiceWaitCount. Also, the setup does not check whether the service has set the state to SERVICE_START_PENDING/SERVICE_STOP_PENDING before beginning this wait, which can contribute to why InstallShield 10.5 and 11.0 setups wait a long time before re-checking the state of the service.
- On the second and subsequent times that this point is reached, the setup checks the dwCheckPoint against the last checkpoint. If the checkpoint value has not changed and the state of the service has not changed, the wait ends. The function checks the services state one last time and returns success or failure depending on whether the service reached the desired state.
- The setup repeats steps 2-5 until one of the above conditions causes the wait to end.
Related Articles
What is the Difference Between a .NET Service and an NT Service? 3Number of Views Cannot Control an Existing NT Service 4Number of Views Workaround Issues with Trialware Protection; the InstallShield Activation Service; .NET, Java, PowerBuilder, or Other Inte… 9Number of Views Digital Signing Patch for InstallShield 2015 SP2 and Above 23Number of Views SQL script to create custom properties for FlexNet Manager Suite 2015 6Number of Views
Hi, I am Reva - Ask me anything.
No new updates
Thanks for the feedback!
Your feedback has been saved.Rate this response:
Add Additional feedback ( Optional )
Are you sure you want to cancel
the case creation?
Are you sure you want to cancel the case creation?
Are you sure you want to close this case
| Products | Region | Phone Numbers |
|---|---|---|
| FlexNet Operations FlexNet Embedded FlexNet Publisher FlexNet Connect FlexNet Code Insight InstallAnywhere InstallShield |
North America * |
+1 630-332-2513 (toll) +1 877-279-2853 (toll-free in North America) |
| Europe * |
+44 1925 944367 (toll) +44 800 047 8642 (toll-free in Europe) |
|
| Japan * | +81 3-4540-5335 (select option 2) | |
| Australia * |
+61 3 9895 2177 +61 1800 560 603 (toll-free in Australia) |
|
|
Usage Intelligence (formerly
Revulytics) Compliance Intelligence |
Please use the Case Portal to submit your support ticket or reach out to your Revenera contact. | |
Case id: 00001065
Activity: Status change: 2 hours ago