I've got a service that I need to start as a different user to 'Local System'
There is a user specific PATH I need to add to the default path in order for the service to work correctly.
The default PATH is A;B;C; I've setup the users PATH X; so that when the user logs on interactively the effective PATH is A;B;C;X; This was done by setting HKEY_USERS\XXXXXXX\Environment\Path
All paths are on local hard drives.
When the service starts as the user I can watch it search for needed DLLs with ProcMon. It is only searching A;B;C; when started as a service.
I've tried altering the service type from 0x10 to 0x110 which should allow desktop interaction to see if that would load the users environment, but it didn't seem to help.
Should Windows be loading the environment settings for a user when starting services? Is there a workaround if this is the default behaviour?
Thanks
MS has a program that runs any program as a service. One of the parameters is
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\<name>\Parameters\AppDirectory
, although this may only apply to these wrapped services.It's Windows Server 2003 specific, but all the same I think this may answer your question: http://support.microsoft.com/kb/887693
Have you tried using SRVANY turn a script such as a batch file into a service and set the environment there before calling out to your desired app? Note: you may concede service stop/start/restart control if the script backgrounds subsequent processes and exits, since the service controller will be checking to see if the script itself is "running." You could also consider reading PATH from the user registry in the script and using its contents so that the env isn't hardcoded in the script itself.
Just to close this out.
I wrote this in a generic format as I suspected I was dealing with a generic Windows service issue.
However it turns out that this is an issue with the service executeables themselves. It appears that the reading of the system path and the user path is somehow depandant on the service executable.
I have two services from the same vendor, one of them reads both the system and user path whereas the other just reads the system path.