Skip to content →

The Allens Posts

Windows Services Running as Local System and Environment Variables

As sometimes happens I installed an application on a Windows server and several days later another program stopped working.

I did my research and was able to determine that the installer for this new program had altered my PATH variable such that a specific DLL was now loading from the wrong place with an incompatible version causing the old program to stop working. Fix the path – everything works. All in a day’s work.

Except…

While I was able to successfully run the program from the command prompt the actual use was different. In fact this program was called from an Apache module that was shelling out to it. In this context the program was still failing. After checking to see if there was some Apache setting that was controlling the PATH variable and finding out that you can’t actually change environment variables in Apache on Windows I was able to confirm that the PATH value in the Apache context was different than the system PATH.

Now I knew that if you change the system PATH you need to close and reopen your command windows to reinitialize the environment variables so I assumed that restarting the Apache service would cause the same thing to happen. Not so much.

As it turns out my Apache service was running as Local System and evidently all the environment variables are set at startup time. That meant I needed to reboot the server. Unfortunately I can’t do that until our maintenance window several days from now and people need the function to work today.
Luckily there were several layers of code between Apache and the actual program that was failing. One layer was a C# application, so making use of the Environment.SetEnvironmentVariable("PATH", newPath, EnvironmentVariableTarget.Process) and then shelling out I was able to temporarily change the PATH to something that will work.

Now I just need to remember I did this 2 years from now when something else changes…

Comments closed

Who, what, when, why, how

I’ve written in a number of places before, but as time marches on previous locations make less sense than they use to. This is my new spot.

  • Who: I’m Wayne.
  • What: I run software based businesses.
  • When: I started my professional journey in 1989 when I went full time in my own software contracting/consulting company.
  • Why: I like solving problems and helping people.
  • How: I am a pragmatist. I have an affinity towards agile/lean

There of course is more to a person than what they do professionally

  • I’m happily married with 2 great kids
  • I enjoy reading science fiction, riding motorcycles and brewing beer (not all at the same time).
  • I’ve traveled more than the average bear, but less than some. I plan on traveling more.
Comments closed