简体   繁体   中英

NSIS $TEMP Has Different Value

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?

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM