[英]Get NSIS Variable for %ALLUSERSPROFILE%
Is there a NSIS variable for %ALLUSERSPROFILE%
? %ALLUSERSPROFILE%
是否有NSIS变量?
If not do you know how I can obtain this environment variable using NSIS code? 如果不是,您是否知道如何使用NSIS代码获取此环境变量?
Note: If I use ReadEnvStr $R7 "ALLUSERSPROFILE"
, $R7
contains C:/ProgramData
because the installer has requested elevated privileges ( RequestExecutionLevel admin
). 注意:如果我使用
ReadEnvStr $R7 "ALLUSERSPROFILE"
,则$R7
包含C:/ProgramData
因为安装程序已请求提升的特权( RequestExecutionLevel admin
)。 This is sooo frustrating! 这太令人沮丧了!
Starting with Vista %ALLUSERSPROFILE% is %SystemDrive%\\ProgramData. 从Vista开始,%ALLUSERSPROFILE%是%SystemDrive%\\ ProgramData。 Some of the things that used to be under All Users was moved to %Public% and the rest is in %ProgramData%.
以前位于“所有用户”下的某些内容已移至%Public%,其余内容移至%ProgramData%。
There are several ways to get this directory but they should all give you the same answer: 有几种获取此目录的方法,但是它们都应该给您相同的答案:
ReadEnvStr $0 "ALLUSERSPROFILE"
DetailPrint %ALLUSERSPROFILE%=$0
System::Call 'userenv::GetAllUsersProfileDirectory(t.r0,*i${NSIS_MAX_STRLEN})i.r1'
DetailPrint GetAllUsersProfileDirectory=$0
; In Vista+ %ALLUSERSPROFIL% and CSIDL_COMMON_APPDATA is the same directory:
SetShellVarContext all
DetailPrint All:Appdata=$AppData
!define FOLDERID_ProgramData {62AB5D82-FDC1-4DC3-A9DD-070D1D495D97}
System::Call 'shell32::SHGetKnownFolderIDList(g"${FOLDERID_ProgramData}", i0x1000, i0, *i.r1)i.r0'
${If} $0 == 0
System::Call 'shell32::SHGetPathFromIDList(ir1,t.r0)'
System::Call 'ole32::CoTaskMemFree(ir1)'
DetailPrint SHGetKnownFolderIDList=$0
${EndIf}
To expand on @Anders reply, you could also use SHGetSpecialFolderPath and make a simple one line call to receive the path to a folder on the operating system. 要扩展@Anders答复,还可以使用SHGetSpecialFolderPath并进行简单的一行调用以接收操作系统上文件夹的路径。
System::Call 'shell32::SHGetSpecialFolderPath(i $HWNDPARENT, t .r1, i 0x23, i0)i.r0'
Use it with CSIDL Values , and you can simply call a function and pop the return. 将它与CSIDL Values一起使用,您可以简单地调用一个函数并弹出返回值。
Function ".OnInit"
System::Call 'shell32::SHGetSpecialFolderPath(i $HWNDPARENT, t .r1, i 0x23, i0)i.r0'
pop $1
MessageBox MB_OK|MB_ICONINFORMATION "$1"
FunctionEnd
Section ""
; blank section (so the script runs)
SectionEnd
This will return C:\\ProgramData (Vista+) or C:\\Documents and Settings\\All Users\\Application Data (XP) into $1 and display a Message Box showing the path. 这会将C:\\ ProgramData(Vista +)或C:\\ Documents and Settings \\ All Users \\ Application Data(XP)返回 $ 1,并显示一个显示路径的消息框。
By switching up the CSIDL Value ( 0x23 ) you can return the path to a bunch of different system folders. 通过切换CSIDL值( 0x23 ),您可以将路径返回到一堆不同的系统文件夹。
Here are some common CSIDL Values that you can use to return the path: 以下是一些可用于返回路径的常见CSIDL值:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.