2

I'm assisting one of our testers in troubleshooting a configuration problem on a Windows XP SP3 system. Our application uses an environment variable, called APP_HOME, to refer to the directory where our application is installed. When the application is installed, we utilize the following environment variables:

APP_HOME = C:\application\
PATH = %PATH%;%APP_HOME%bin

Now, the problem comes in that she's working with multiple versions of the same application. So, in order to switch between version 7.0 and 8.1, for example, she might use:

APP_HOME = C:\application_7.0\ (for 7.0)

and then change it to:

APP_HOME = C:\application_8.1\ (for 8.1)

The problem is that once this change is made, the PATH environment variable apparently still is looking at the old expansion of the APP_HOME variable. So, for example, after she has changed APP_HOME, PATH still refers to the 7.0 bin directory.

Any thoughts on why this might be happening? It looks to me like the PATH variable is caching the expansion of the APP_HOME environment variable. Is there any way to turn this behavior off?

jwir3
  • 155
  • 1
  • 2
  • 10

2 Answers2

4

The changes are not dynamic. When you change environment variables for Windows then other processes need to be restarted in order for them to operate in the new environment.

When a process starts it'll expand the value of your APP_HOME variable and append it to your PATH. You'll need to restart the process to reinitialize, or reset the PATH variable so it reads the new value of APP_HOME.

squillman
  • 37,883
  • 12
  • 92
  • 146
  • Hm, well the problem we're actually experiencing doesn't have to do with a process that is already running. If she runs our application, by opening a new command shell after changing the environment variable and typing the application command (e.g. app.exe, which is in %APP_HOME%bin) it uses the one from the old directory (e.g. 7.0). So, it doesn't seem like we have any old processes that haven't been restarted... – jwir3 Feb 09 '11 at 17:48
  • @jwir3 How is she setting the new value of APP_HOME? Via cmd line or through system settings? – squillman Feb 09 '11 at 17:49
  • @squillman: Through system settings - Control Panel->System->Advanced->Environment Variables. – jwir3 Feb 09 '11 at 17:57
  • 1
    Also, I forgot to mention - it actually resets back to the 7.0 version if she logs out and logs back on. So, something really strange seems to be going on here. – jwir3 Feb 09 '11 at 17:58
  • @jwir3 Sounds like it's getting set both at the user level and at the system level. Sounds like there's a system variable that's set to 7.0 but she's setting a user variable. Can you verify that that's not happening? – squillman Feb 09 '11 at 18:01
  • @squillman Well, I just looked at her machine right now through the Control Panel, Advanced, Environment Variables. There isn't a version of the APP_HOME in the User Variables, but rather only in the system variables. She demonstrated how she changes it to me by changing the system environment variable. She said that if she simply modifies the path (doesn't actually change it), but simply edits it and then clicks 'Ok', the path then resolves to the correct version of the APP_HOME variable. – jwir3 Feb 09 '11 at 18:07
  • 1
    @jwir3 ok, then It's as I was saying. By "editing" the PATH variable you're forcing Windows to refresht it. Windows will reread your APP_HOME value and incorporate it into the new value for PATH. Just resetting APP_HOME doesn't force a refresh of other variables that rely on it. – squillman Feb 09 '11 at 18:14
  • Ok, but it seems odd that the 15+ developers that work here use the same process, but she seems to be the only one exhibiting this behavior? Any idea why the rest of us aren't seeing this? – jwir3 Feb 09 '11 at 18:16
  • @jwir3 Sorry, was just in a meeting. Assuming the exact same process, I can't think of why there would be a discrepancy. – squillman Feb 09 '11 at 19:25
  • @squillman No worries. Thanks for your help. I appreciate it. – jwir3 Feb 09 '11 at 20:01
1

This seems to be an IIS bug. A restart will fix your problem. Note that killing w3wp and recycling the app pool will not do anything.

You can check to make sure w3wp uses the correct environment path via processexplorer.exe

HopelessN00b
  • 53,795
  • 33
  • 135
  • 209
ctong
  • 11
  • 1
  • 1
    I think this is not `IIS` bug. Environment variables are "inherited" from parent process and `w3wp.exe` is hosted by `svchost.exe` which "knows" nothing about changes. – Eugene Nov 26 '13 at 06:24
  • Thanks. This has shown me how to inspect environment variables attached to a process. – Frank Fu Jun 21 '23 at 02:23