"All users"/"Current User Only"
How I can add an option in the installer, which asks me if I want to install it for "All users" or "Current user only".
Archive: "All users"/"Current User Only"
"All users"/"Current User Only"
How I can add an option in the installer, which asks me if I want to install it for "All users" or "Current user only".
Hi
Take a look at SetShellVarContext in help
This is good, but how I can handle if the user clicks on "All users" or "Current User Only". And then to "transfer" to the lines of the chosen method.
With yor own Custom Page I think
I've done the following, you might use it as a template to achieve what you're looking,
!define CUST_INI "$PLUGINSDIR\custom.ini"
!define APP_NAME "My Application"
!define DrawCustomPage "Call DrawCustomPage"
Name "${APP_NAME}"
OutFile "Test.exe"
ShowInstDetails show
InstallDir "$PROGRAMFILES\${APP_NAME}"
!include "LogicLib.nsh"
!include "mui.nsh"
var myvar
Function MUI_PageUserDetailsCreate
!insertmacro MUI_HEADER_TEXT "Customer Information" \
"Please enter your information."
push $1
InstallOptions::Dialog '${CUST_INI}'
pop $1
pop $1
FunctionEnd
Function MUI_PageUserDetailsLeave
Push $1
ReadINIStr $1 '${CUST_INI}' "field 7" "state"
${if} $1 == 1
StrCpy $myvar "all"
${else}
StrCpy $myvar "current"
${endif}
Pop $1
FunctionEnd
!macro MUI_PAGE_USERINFO
Page Custom MUI_PageUserDetailsCreate MUI_PageUserDetailsLeave
!macroend
!insertmacro MUI_PAGE_USERINFO
!insertmacro MUI_PAGE_LICENSE "${NSISDIR}\Docs\Modern UI\License.txt"
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_LANGUAGE "English"
Section "boo"
SetOutPath "$INSTDIR"
${if} $myvar == "all"
SetShellVarContext all
${elseif} $myvar == "current"
SetShellVarContext current
${endif}
DetailPrint "$APPDATA"
SectionEnd
Function .onInit
${DrawCustomPage}
FunctionEnd
Function DrawCustomPage
push $0
push $1
push $2
StrCmp "$PLUGINSDIR" "" 0 +2
InitPluginsDir
GetTempFileName $0
Rename $0 '${CUST_INI}'
ClearErrors
ReadRegStr $0 HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion" "RegisteredOwner"
IfErrors is_NT
WriteIniStr '${CUST_INI}' 'Settings' 'NumFields' '5'
ReadRegStr $1 HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion" "RegisteredOrganization"
goto DrawPage
is_NT:
ClearErrors
ReadRegStr $0 HKLM "Software\Microsoft\Windows NT\CurrentVersion" "RegisteredOwner"
ReadRegStr $1 HKLM "Software\Microsoft\Windows NT\CurrentVersion" "RegisteredOrganization"
ReadRegStr $2 HKCU "Software\Microsoft\Windows\CurrentVersion\Explorer" "Logon User Name"
WriteIniStr '${CUST_INI}' 'Settings' 'NumFields' '8'
DrawPage:
WriteIniStr '${CUST_INI}' 'Field 1' 'Type' 'GroupBox'
WriteIniStr '${CUST_INI}' 'Field 1' 'Left' '0'
WriteIniStr '${CUST_INI}' 'Field 1' 'Top' '0'
WriteIniStr '${CUST_INI}' 'Field 1' 'Right' '-1'
WriteIniStr '${CUST_INI}' 'Field 1' 'Bottom' '90'
WriteIniStr '${CUST_INI}' 'Field 1' 'Text' 'Customer Information'
WriteIniStr '${CUST_INI}' 'Field 2' 'Type' 'Label'
WriteIniStr '${CUST_INI}' 'Field 2' 'Left' '14'
WriteIniStr '${CUST_INI}' 'Field 2' 'Top' '16'
WriteIniStr '${CUST_INI}' 'Field 2' 'Right' '-14'
WriteIniStr '${CUST_INI}' 'Field 2' 'Bottom' '26'
WriteIniStr '${CUST_INI}' 'Field 2' 'text' 'User Name:'
WriteIniStr '${CUST_INI}' 'Field 3' 'Type' 'Text'
WriteIniStr '${CUST_INI}' 'Field 3' 'Left' '14'
WriteIniStr '${CUST_INI}' 'Field 3' 'Top' '26'
WriteIniStr '${CUST_INI}' 'Field 3' 'Right' '-14'
WriteIniStr '${CUST_INI}' 'Field 3' 'Bottom' '38'
WriteIniStr '${CUST_INI}' 'Field 3' 'State' '$0'
WriteIniStr '${CUST_INI}' 'Field 3' 'Minlen' '2'
WriteIniStr '${CUST_INI}' 'Field 3' 'ValidateText' 'Error'
WriteIniStr '${CUST_INI}' 'Field 4' 'Type' 'Label'
WriteIniStr '${CUST_INI}' 'Field 4' 'Left' '14'
WriteIniStr '${CUST_INI}' 'Field 4' 'Top' '44'
WriteIniStr '${CUST_INI}' 'Field 4' 'Right' '-14'
WriteIniStr '${CUST_INI}' 'Field 4' 'Bottom' '54'
WriteIniStr '${CUST_INI}' 'Field 4' 'Text' 'Organization:'
WriteIniStr '${CUST_INI}' 'Field 5' 'Type' 'text'
WriteIniStr '${CUST_INI}' 'Field 5' 'Left' '14'
WriteIniStr '${CUST_INI}' 'Field 5' 'Top' '54'
WriteIniStr '${CUST_INI}' 'Field 5' 'Right' '-14'
WriteIniStr '${CUST_INI}' 'Field 5' 'Bottom' '66'
WriteIniStr '${CUST_INI}' 'Field 5' 'State' '$1'
WriteIniStr '${CUST_INI}' 'Field 5' 'MinLen' '2'
WriteIniStr '${CUST_INI}' 'Field 5' 'ValidateText' 'Error'
WriteIniStr '${CUST_INI}' 'Field 6' 'Type' 'label'
WriteIniStr '${CUST_INI}' 'Field 6' 'Left' '14'
WriteIniStr '${CUST_INI}' 'Field 6' 'Top' '100'
WriteIniStr '${CUST_INI}' 'Field 6' 'Right' '-14'
WriteIniStr '${CUST_INI}' 'Field 6' 'Bottom' '112'
WriteIniStr '${CUST_INI}' 'Field 6' 'Text' 'Install this application for:'
WriteIniStr '${CUST_INI}' 'Field 7' 'Type' 'RadioButton'
WriteIniStr '${CUST_INI}' 'Field 7' 'Left' '60'
WriteIniStr '${CUST_INI}' 'Field 7' 'Top' '114'
WriteIniStr '${CUST_INI}' 'Field 7' 'Right' '-1'
WriteIniStr '${CUST_INI}' 'Field 7' 'Bottom' '126'
WriteIniStr '${CUST_INI}' 'Field 7' 'State' '1'
WriteIniStr '${CUST_INI}' 'Field 7' 'Flags' 'GROUP'
WriteIniStr '${CUST_INI}' 'Field 7' 'Text' 'Anyone who uses this computer (all users)'
WriteIniStr '${CUST_INI}' 'Field 8' 'Type' 'RadioButton'
WriteIniStr '${CUST_INI}' 'Field 8' 'Left' '60'
WriteIniStr '${CUST_INI}' 'Field 8' 'Top' '128'
WriteIniStr '${CUST_INI}' 'Field 8' 'Right' '-1'
WriteIniStr '${CUST_INI}' 'Field 8' 'Bottom' '140'
WriteIniStr '${CUST_INI}' 'Field 8' 'State' '0'
WriteIniStr '${CUST_INI}' 'Field 8' 'Text' 'Only for me ($2)'
pop $2
pop $1
pop $0
Functionend