1

I have Windows 7 Pro x64.

During the last one or two weeks, it happens sometimes to me that various applications cannot write to temporary directory. I've found that this is because the TEMP environment variable is set to the system value (C:\Windows\TEMP usually, I have it set differently), and not to the user value (B:\Users\%USERNAME%\Temp in my case). Also the explorer.exe process has TEMP set incorrectly, when this problem occurs.

Originally I thought that the incorrect TEMP value is set during winlogon, but it turns out this is not always the case. It's also important to say that this happens with several user profiles on the same computer, not only with my own profile.

Yesterday, when this happened again, I restarted the computer, logged in and checked that the explorer.exe process has this TEMP variable set correctly. Then I started several other applications, all have TEMP set correctly too. But today, after waking up the notebook from sleep, explorer.exe has incorrect TEMP value again, and hence every other newly started application inherits it! Its evidently still the same process as yesterday, as its a parent process for most applications, including those that were started yesterday and still have TEMP set correctly! I'm perplexed :-(.

Questions: How can anything like this happen? What can this strange behaviour be caused by? How to solve the problem?

The problem is frustrating as I always have to close everything and perform logout&login.

Remarks:

  • I use ProcessExplorer to see how the current environment of individual processes looks like.
  • I don't thing the memory gets corrupted. Because then TEMP would be filled with a nonsense, not with the valid system TEMP value.
  • There's plenty of space on the disks.
  • Nor I think that my profile is corrupted. Because the same I have notices with other profiles as well, and it doesn't happen always.
14
  • Read over this for an explanation: environmentvariables.org/Temp maybe it will help clarify for you some. Depending on the security context of something running that uses that variable, one or the other may be used per the correlated alias/environmental variable pointer. So if it runs as SYSTEM for example it may use C:\Windows\TEMP whereas using as a user account may use the profile temp path. Aug 15, 2017 at 12:24
  • Thanks for the link, but I don't see there anything useful. In particular, how is it possible that explorer.exe process changes its TEMP value during time? And how to prevent that?
    – xarx
    Aug 15, 2017 at 12:57
  • 1
    Set a different variable name other than %TEMP% and use it instead: SET dTemp=%SYSTEMROOT%\TEMP Then use %dTemp% in the rest of your script instead. Quick workaround I suppose in terms of how to prevent other than controlling the runtime/execution time security context of whatever is executing the process that uses the %TEMP% variable. Aug 15, 2017 at 13:18
  • I'm not sure I understand you. I'm not having a problem with a script but with Windows. Applications in Windows have problems when they try to write to the TEMP folder, because the TEMP variable in their environment is set to wrong location. Not my script (I'm writing none currently).
    – xarx
    Aug 15, 2017 at 14:27
  • Check your system variables: you will probably find that TEMP is set to the system default in the system variables and to your setting in the user variables (PC -> Properties -> Advanced System Settings -> Advanced tab -> Environment Variables... button). How are you checking Explorer's TEMP value? System processes (eg launched by a service) will use the system TEMP setting, while user processes will use your user TEMP.
    – AFH
    Aug 15, 2017 at 14:29

0

You must log in to answer this question.

Browse other questions tagged .