View Full Version : ServiceStartService and SERVICE_IS_PARAMS

02-20-2005, 12:55 AM
Can anyone help me figure out how to make my call to ServiceStartService work properly.

By default this function attempts to start the service and waits (infinitly) until the service starts successfully.

I would like to have the function time out after say 6 seconds. I am trying to use SERVICE_IS_PARAMS.nStartServiceWaitCount = 6 but this does not seem to have the affect I am looking for.

According to the help file, this value is the StartService timeout in seconds. But if I set this to anything (even 1000), the ServiceStartService returns immediately with an error.

Here is my code snippet:
SERVICE_IS_PARAMS.nStartServiceWaitCount = 6;
if ServiceStartService('myservice', '') < ISERR_SUCCESS then
MessageBox('Error starting service', SEVERE);

This always shows the error message, even though the service itself is started successfully.

Is there another setting that I need to make to get the ServiceStartService to use the StartServiceWaitCount?


06-20-2005, 04:14 PM
I think that the SERVICE_IS_PARAMS documentation should indicated that the nStartServiceWaitCount and the nStopServiceWaitCount should be specified in milliseconds. When I provide a value that is shorter than the time it takes for my service to start, then the ServiceStartService function fails and the GetExtendedError returns a -1. If I increase the value of the nStartserviceWaitCount sufficently then the ServiceStartService returns ISSUCCESS. So a -1 in this case indicates that the wait count limit was hit, and by experimentation it appears to me that the value is in milliseconds and not seconds as documented. I would also note that the underlying Win32 API that is being called takes a value in milliseconds as well.

06-28-2005, 04:58 PM
My prior post stating that the value should be in milliseconds is incorrect.

Further investigation confirmed that if either the stop or start 'wait' parameters are set to any value other than INFINITE (-1) then the function returns a failure and the GetExtendedErrInfor returns -1 as the nvError code. In some cases however the service still starts or stops, but then sometimes that is not the case.

I reported this behavior to Support and they confirmed that this is a known issue that is being worked on under workorder #1-1BHUXV. They did not offer any workaround in the mean time.

Richard Winks
11-22-2005, 03:04 PM
Here is the kludge I used

SERVICE_IS_PARAMS.nStartServiceWaitCount=<some value>
if service state is running then done
else wait a reasonable time
if service state is still not running then error.

Peter Kosenko
03-06-2008, 04:32 PM
This is not good. I have been thinking of using ServiceStartService() in an InstallShield 2008 installer. Does anyone know whether the issue has been fixed for later versions of InstallShield?

It seems to me that the function should return after a specified time, whether or not the service has started, and give a return value that allows you to tell the user whether or not to check the service. And it should run asynchronously so that the installer doesn't hang.

I can't tell whether the InstallShield 2008 help has been updated for a fix. It doesn't look like it.