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?


  • Is x: a physical disk that is always present, or a mapped network drive? – Mark Henderson Aug 24 '09 at 5:45
  • x; is a physical disk. – Cephas Aug 24 '09 at 5:50
  • Interesting... Just for reference, if it's helpful, I run a service (winamp) under a domain account with a network drive mapped using the AD account options to provide unc-less ajaxamp with an M: for the music - and that works fine. It'll map the M: just by starting the service as that user. – Oskar Duveborn Sep 8 '09 at 8:02

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.

  • The Parameters sub keys are specific to the service exe, in this case SRVANY.EXE It doesn't help in this case. – Cephas Aug 25 '09 at 1:06
  • Each service, even if running via SRVANY, has it's own registry entry, and I have run SRVANY services from two different directories. I implemented that setting to resolve a problem in at least one of them; I don't recall if it necessary for the second, or just following my example. It would seem strange if it picked an arbitrary directory from those specified. – Justin Love Aug 26 '09 at 14:21

It's Windows Server 2003 specific, but all the same I think this may answer your question: http://support.microsoft.com/kb/887693

  • Server has been rebooted. The service is reading the system environment successfully. Its just not reading the user specific environment variables. – Cephas Aug 25 '09 at 1:17

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.