ServiceExistsService InstallScript function doesn't seem to always work within Vista

If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

My typical use case for this type of API call is an AppSearch extension pattern to facilitate allowing a LaunchCondition to abort the install if a certain service ( say w3svc ) isn't installed and/or running. I give different error messages to instruct the user whether he needs to install IIS or simply make sure that it is running.

I really need to be able to run these API calls from Immeadiate execution and without context elevation. Thanks for opening the WO and no thanks to Microsoft for still having a half baked AppSearch pattern after 10 years of feedback from customers.

Thanks a Bunch

Thanks to all that have replied. While you guys were testing I tried a modified version of the code found under 'Set Start Mode of an NT Service' in http://www.installsite.org/pages/en/isp_svc.htm as was suggested in an earlier post. So I am now getting the info out of the registry instead of using ServiceExistsService and ServiceGetServiceState. It looks like this is going to work just fine.
You have my sincere thanks and respect.

You can technically ( and usually but not always reliably ) query configuration ( but not state ) data regarding a service by looking at the registry, but there is a problem with that.

The SCM ( Service Control Manager ) is the official API for getting this information. The data that you see in the registry is really private data for that API. It shouldn't be directly relied upon. For example someone could create the registry key for a service and not reboot. The service does not technically exist yet because the SCM doesn't know about it. The same goes for removing a service. Someone could delete that registry key but the service still exists until after a reboot.

You should really always go through the SCM ( and allow IT to update it's private data storage ) and not directly modify it's private data.... despite the example you are seeing from InstallSite! Calling the SCM API will always give you the authorative answer on what IT thinks is the status of a service.

Running from a bootstrapper (Setup.exe) with "Highest Level available" the ServiceExistsService functions within the UISequence and ExecuteSequence, but upon ARP-Repair or auto-repair ServiceExistsService doesn't function properly. Unfortunately I need this to be an immediate action.

Per Macrovision support:

At the moment, the way our InstallScript engine checks the state of a service requires that the user has elevated privileges. With the changes in the way that Vista manages Administrator rights, we receive improper failure cases for attempting to locate or utilize a service.

The best workarounds for this issue are to either set the setup.exe's Required Execution Level to as Administrator or only check for services in Deferred in system context custom actions which also means that move the CA from 'Install UI' to 'Install Execute' and executed it "After InstallInitialize", which won't have this issue.