2

I have been noticed $TEMP param has different value when you:

  • run the installer.exe manually (by double clicking)
  • run from Application with Admin rights.

Running manually will result $TEMP = C:/Users/username/AppData/Local/Temp

Running from App with Admin rights = C:/Windows/Temp

CONDITION:

I have an installer that requires system reboot to finish the process.

To achieve that, I make a copy of installer in the $TEMP, and put the path in RunOnce

PROBLEM:

The function works fine (after reboot, the program is updated with new version).

However, at the end of installation process, I am unable to delete the copy of installer because the $TEMP = C:/Users/username/AppData/Local/Temp when running the installer by RunOnce.

In fact, the copy of installer is located in C:/Windows/Temp

QUESTION:

Is it possible to force the $TEMP to always be = C:/Windows/Temp ?

Is there any better solution to workaround the case of installation with system reboot?

undo
  • 31
  • 3

1 Answers1

5

NSIS gets its $Temp variable like this:

First it tries GetTempPath. That function tries (in order): %TMP%, %TEMP%, %USERPROFILE%, and %WINDIR%, and it returns the first variable that exists.

NSIS then tries to write to this directory and if that fails NSIS uses %WINDIR%\Temp.

Admin vs non-admin nor UAC elevation is not really the cause of what you are seeing. Sounds more like a configuration or Anti-Virus issue.

You can force $Temp to a specific directory if you really want to in NSIS 3:

Function .onInit
UnsafeStrCpy $Temp "$Windir\Temp"
CreateDirectory $Temp
/* 
#--# Uncomment to apply the same %TEMP% to child processes #--#
System::Call 'KERNEL32::SetEnvironmentVariable(t"TEMP",t"$Temp")'
System::Call 'KERNEL32::SetEnvironmentVariable(t"TMP",t"$Temp")'
*/
FunctionEnd

I don't actually understand your issue though because the RunOnce entry can tell what it's path is by using $ExePath.

Anders
  • 97,548
  • 12
  • 110
  • 164
  • Yes, I guess it's not really because of Admin rights. Because the installer is executed by other app (update manager), which is out of my scope. So, I'm not really sure how it becomes C:/Windows/Temp. Anyway, I did a workaround by putting the copy of installer in ProgramFiles, instead of Temp. Thanks for your comments. – undo Nov 28 '18 at 02:41
  • It probably inherited this temp from the update manager. You can inspect the environment of a process with Process Explorer. – Anders Nov 28 '18 at 03:07