2

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

Cephas
  • 443
  • 1
  • 4
  • 10
  • Is x: a physical disk that is always present, or a mapped network drive? – Mark Henderson Aug 24 '09 at 05:45
  • x; is a physical disk. – Cephas Aug 24 '09 at 05: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 08 '09 at 08:02

4 Answers4

3

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.

Justin Love
  • 554
  • 3
  • 9
  • 18
  • 1
    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 01: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
0

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

Maximus Minimus
  • 8,987
  • 2
  • 23
  • 36
  • 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 01:17
0

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.

astrostl
  • 690
  • 4
  • 11
0

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.

Cephas
  • 443
  • 1
  • 4
  • 10