简体   繁体   English

为%ALLUSERSPROFILE%获取NSIS变量

[英]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值:

  • 0x0 Desktop 0x0桌面
  • 0x2 Programs 0x2程序
  • 0x5 My document 0x5我的文件
  • 0x6 Favorites 0x6收藏
  • 0x7 Startup 0x7启动
  • 0x8 Recent documents 0x8最近文件
  • 0x9 Sendto documents 0x9发送至文档
  • 0x10 Desktop Directory 0x10桌面目录
  • 0x11 My Computer 0x11我的电脑
  • 0x14 Fonts directory 0x14字体目录
  • 0x15 Windows Template 0x15 Windows模板
  • 0x20 Internet Cache 0x20 Internet缓存
  • 0x21 Cookies 0x21饼干
  • 0x22 History 0x22历史
  • 0x23 Common Application Data 0x23通用应用数据
  • 0x25 System 0x25系统
  • 0x26 Program Files 0x26程序文件
  • 0x27 My Pictures 0x27我的图片
  • 0xb StartMenu 0xb开始菜单
  • 0xd My Music 0xd我的音乐
  • 0x1a Application Data 0x1a应用数据
  • 0x1c Local Application Data 0x1c本地应用程序数据
  • 0x2b Common Program Files 0x2b通用程序文件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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