Tuesday, May 21, 2013

Temporary environment variables precedence in Windows

The user environment variables always have precedence over the system environment variables for the process run by the particular user.

In relation to the temporary folders, the TMP environment variable has a precedence over the TEMP environment variable (legacy reasons dating to DOS). So to sum up the temporary folders environment variable precedence (top to bottom) for the currently logged in user is:
  • User %TMP%  (Highest precedence)
  • System %TMP%
  • User %TEMP%
  • System %TEMP% (Lowest precedence)
You can verify the precedence using:
  • Command prompts echo %ENVIRONMENT VARIABLE%
  • Java's [System.getProperty("java.io.tmpdir")]
  • C# [Path.GetTempPath()]