为%ALLUSERSPROFILE%获取NSIS变量 [英] Get NSIS Variable for %ALLUSERSPROFILE%

查看:212
本文介绍了为%ALLUSERSPROFILE%获取NSIS变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

%ALLUSERSPROFILE%是否有NSIS变量?

Is there a NSIS variable for %ALLUSERSPROFILE%?

如果不知道,我如何使用NSIS代码获取此环境变量?

If not do you know how I can obtain this environment variable using NSIS code?

注意:如果我使用ReadEnvStr $R7 "ALLUSERSPROFILE",则$R7包含C:/ProgramData,因为安装程序已请求提升的特权(RequestExecutionLevel admin).这太令人沮丧了!

Note: If I use ReadEnvStr $R7 "ALLUSERSPROFILE", $R7 contains C:/ProgramData because the installer has requested elevated privileges (RequestExecutionLevel admin). This is sooo frustrating!

推荐答案

从Vista开始,%ALLUSERSPROFILE%是%SystemDrive%\ ProgramData.以前位于所有用户"下的某些内容已移至%Public%,其余部分已移至%ProgramData%.

Starting with Vista %ALLUSERSPROFILE% is %SystemDrive%\ProgramData. Some of the things that used to be under All Users was moved to %Public% and the rest is in %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}

这篇关于为%ALLUSERSPROFILE%获取NSIS变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆