我正在寻找当前用户%APPDATA%
文件夹的路径。
注意:我知道变量$APPDATA
,但是如果你用RequestExecutionLevel admin
运行安装程序,那么$APPDATA
将指向管理员漫游文件夹,而不是当前用户的应用程序数据文件夹。
我需要找出当前用户的%APPDATA%路径,以便我可以将文件写入他们的漫游目录。有人知道我怎么知道吗?
RequestExecutionLevel admin
Section "Main"
MessageBox MB_OK "AppData is: $APPDATA" # knowtice that its the path to the admins folder not the current user's
SectionEnd
"当前用户"这个词是模棱两可的,你的意思是:
- 您从
WTSQueryUserToken()
获得的用户?(进程) - shell任务栏运行的用户名?(
GetShellWindow()
) 启动安装进程的用户(父进程)?
如果你喜欢runas,所有这些都可以是不同的用户!
Harry Johnston的评论非常正确,一旦你开始混合%ProgramFiles%和%AppData%和/或HKLM和HKCU,你的设置在多用户场景中就会被破坏。当不同的用户启动应用程序时会发生什么?他们不会把你的文件放在他们的%AppData%中。
如果插件安装/注册在全局位置,您可以在%ProgramFiles%, %CommonProgramFiles%或%ALLUSERSPROFILE%中安装AppData "模板"文件,当您的插件第一次以特定用户运行时,您可以将这些文件复制到%AppData%。
Active Setup可以作为另一种选择,但可能需要一个注销/登录周期。
如果你不能实现延迟复制/安装的原因,你剩下的黑客像UAC插件,它给你一些访问用户启动你的安装程序…
好的,谢谢你的建议,但我发现了一个很好的插件,告诉我所有用户目录的位置。我仍然不能找出当前登录的用户,但我可以找出所有非管理员用户,这是非常有用的。
!include "NTProfiles.nsi"
!macro HandleUserProfiles
!define NTProfilePaths::IgnoreLocal
!ifndef __UNINSTALL__
${EnumProfilePaths} HandleUserProfile
!else
${EnumProfilePaths} un.HandleUserProfile
!endif
!macroend
!macro HandleUserProfile prefix
Function ${prefix}HandleUserProfile
Pop $R9
!ifndef __UNINSTALL__
# Copy files to user dir
SetOutPath "$R9AppDataRoamingAutodeskRevitAddins2013" # $APPDATA = C:ProgramData
FILE /r "${INSTALLFILEDIR}AddinsRevit_2013myAddin.addin"
!else
Delete "$R9AppDataRoamingAutodeskRevitAddins2013myAddin.addin"
!endif
# Continue Enumeration
Continue:
Push ""
Return
# Stop Enumeration
Stop:
Push "~" # Any value other than an empty string will abort the enumeration
FunctionEnd
!macroend
!insertmacro HandleUserProfile ""
!insertmacro HandleUserProfile "un."