根据MultiUser.nsh的宏,将根据$MultiUser.InstallMode的值将$INSTDIR设置为下列路径之一
"$LOCALAPPDATA\${MULTIUSER_INSTALLMODE_INSTDIR}""$PROGRAMFILES\${MULTIUSER_INSTALLMODE_INSTDIR}"基本上,宏将$MULTIUSER_INSTALLMODE_INSTDIR附加到$LOCALAPPDATA或$PROGRAMFILES中,并将其用作默认的安装路径。
我只需要为CurrentUser安装模式提供一个稍微不同的路径,即:
"$LOCALAPPDATA\Programs\${MULTIUSER_INSTALLMODE_INSTDIR}"
我怎样才能做到这一点?
如果用户有机会选择installMode,则必须在做出此选择之后设置默认的$INSTDIR值。
发布于 2017-11-07 17:39:46
您可以使用MULTIUSER_INSTALLMODE_FUNCTION回调函数定义进行更改:
Name "MultiUser test"
!define MULTIUSER_INSTALLMODE_INSTDIR "$(^Name)"
!define MULTIUSER_EXECUTIONLEVEL Highest
!define MULTIUSER_INSTALLMODE_FUNCTION onMultiUserModeChanged
!define MULTIUSER_MUI
!include MultiUser.nsh
!include MUI2.nsh
!include LogicLib.nsh
!insertmacro MULTIUSER_PAGE_INSTALLMODE
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_UNPAGE_CONFIRM
!insertmacro MUI_UNPAGE_INSTFILES
!insertmacro MUI_LANGUAGE English
Function .onInit
!insertmacro MULTIUSER_INIT
FunctionEnd
Function un.onInit
!insertmacro MULTIUSER_UNINIT
FunctionEnd
Function onMultiUserModeChanged
${If} $MultiUser.InstallMode == "CurrentUser"
StrCpy $InstDir "$LocalAppdata\Programs\${MULTIUSER_INSTALLMODE_INSTDIR}"
${EndIf}
FunctionEnd
Section
MessageBox MB_OK $InstDir
Quit ; This is just a demo
SetOutPath $InstDir
WriteUninstaller "$InstDir\Uninst.exe"
SectionEnd
Section Uninstall
Delete "$InstDir\Uninst.exe"
RMDir $InstDir
SectionEnd或者更好的是,如果UserProgramFiles已知文件夹可用,可以使用它:
!macro GetUserProgramFiles outvar
!define /IfNDef KF_FLAG_CREATE 0x00008000
!define /IfNDef FOLDERID_UserProgramFiles {5CD7AEE2-2219-4A67-B85D-6C9CE15660CB}
System::Store S
System::Call 'SHELL32::SHGetKnownFolderPath(g "${FOLDERID_UserProgramFiles}", i ${KF_FLAG_CREATE}, p 0, *p .r2)i.r1' ; This will only work on Win7+
${If} $1 == 0
System::Call '*$2(&w${NSIS_MAX_STRLEN} .s)'
System::Call 'OLE32::CoTaskMemFree(p r2)'
${Else}
Push "$LocalAppData\Programs"
${EndIf}
System::Store L
Pop ${outvar}
!macroend
Function onMultiUserModeChanged
${If} $MultiUser.InstallMode == "CurrentUser"
!insertmacro GetUserProgramFiles $InstDir
StrCpy $InstDir "$InstDir\${MULTIUSER_INSTALLMODE_INSTDIR}"
${EndIf}
FunctionEndhttps://stackoverflow.com/questions/47162998
复制相似问题