17

I have a Windows Server 2008 32 bit and when I'm typing %temp% it takes me to ..AppData\Local\Temp\1\ or ..AppData\Local\Temp\2 instead of ..AppData\Local\Temp

I've already checked the Environment Variables and they are ok.

I'm asking that because I have an application that's supposed to copy files to %temp%\my application and instead it copies the files to %temp%\1\my application

Does someone have a solution for that?

Garen
  • 941
  • 2
  • 9
  • 20
shacharsa
  • 351
  • 1
  • 4
  • 12

2 Answers2

24

Explanation, discussion, workarounds, etc, all under the Old New Thing article Why does the name of my TEMP directory keep changing - it ensures multiple terminal services sessions for the same user don't (by default) share a temp directory.

The problem lay in the Administrative Templates\Windows Components\Terminal Services\Temporary folders group policy. If you don't select Do not use temporary folders per session, then these TEMP subdirectories are created. There is also a knowledge base article describing the registry keys behind these group policies.

Personally, I find the first comment in reply to be the most useful:

Why does it matter if the temp location jumps around anyway, it's temporary!

See also

Ian Boyd
  • 246,734
  • 253
  • 869
  • 1,219
Damien_The_Unbeliever
  • 234,701
  • 27
  • 340
  • 448
  • thanks, im now understand it... , ive changed the target folder instead of the %temp% folder – shacharsa Jun 30 '11 at 13:50
  • 2
    Why does it matter if it changes? Because sometimes two programs must rendezvous via a file in the TEMP directory. Not being able to predict the value makes it harder. – e40 Jul 24 '13 at 23:30
  • 2
    @e40 - if the two programs are running in the *same* session, they'll observe the same value. If the two programs are running in *different* sessions, then any interaction between them is probably a bug. – Damien_The_Unbeliever Jul 25 '13 at 05:53
  • 8
    I've run into a case where I end up with a /2 temp folder, but somehow Windows is not creating that folder. So a bunch of stuff starts failing. Some apps - like Process Explorer won't even run as it extracts and runs from temp folder. – Rick Strahl Mar 10 '16 at 11:24
  • This was a weird one to try and Google but I'm glad I found an answer. – codaamok Nov 17 '16 at 13:05
0

Environment variables have 4 contexts:

(do Win+R then type regedit to find the paths below)

  1. System variables (HKLM\System\CurrentControlSet\Control\Session Manager\Environment)
  2. User variables (HKCU\Environment)
  3. Process variables (not stored in the registry)
  4. Volatile variables (HKCU\VolatileEnvironment)

ref: https://rakhesh.com/windows/temp-environment-variable-has-a-2-or-other-number-after-it/

When the Group Policy Do not use temporary folders per session isn't configured or isn't set to Enabled, the system will generate two Volatile Environment variables TEMP & TMP with the same value of the current user's TEMP variable with the addition of an incremental number at the end of the TEMP folder (increments each time the user logs in, check @Damien's answer for details)

If you set the group policy Do not use temporary folders per session to enabled, this behavior will not occur.

Uentee
  • 783
  • 1
  • 7
  • 15