3
votes

I want to create a dual installer for an application, which either installs it as portable or normal version.

For the portable version, I don't want to require admin rights. For the normal version, I need admin rights for adding the application to the start menu and other things.

Is there a way to prompt the user for admin rights when starting the actual installation? Maybe with a plug-in? I'm looking for something like RequestExecutionLevel admin inside a section.

1

1 Answers

1
votes

RequestExecutionLevel highest will force members of the administrator group to elevate while normal users can run it with no UAC interaction. This example does not elevate for you because doing that is tricky, UAC is broken in certain scenarios and it would require more code to do it correctly...

RequestExecutionLevel highest
Var InstMode

!include nsDialogs.nsh
!include Sections.nsh
!include LogicLib.nsh
Page Custom InstallModePageInit InstallModePageLeave
Page InstFiles

Section "StartMenu shortcuts" SEC_SM
; CreateShortcut ...
SectionEnd
Section "" SEC_UNINST
; WriteUninstaller & registry
SectionEnd

Function InstallModePageInit
nsDialogs::Create 1018
Pop $0

${NSD_CreateRadioButton} 20u 30u 100% 12u "Normal install"
Pop $1
${NSD_CreateRadioButton} 20u 50u 100% 12u "Portable install"
Pop $2

${If} $InstMode = 0
    ${NSD_Check} $1
${Else}
    ${NSD_Check} $2
${EndIf}
nsDialogs::Show
FunctionEnd

Function InstallModePageLeave
${NSD_GetState} $2 $InstMode
${If} $InstMode = 0
    !insertmacro SelectSection ${SEC_SM}
    !insertmacro SelectSection ${SEC_UNINST}
    UserInfo::GetAccountType
    Pop $0
    ${If} $0 != "Admin"
        MessageBox mb_iconstop "Administrator privileges required, please restart installer to continue..."
        Abort
    ${EndIf}
${Else}
    !insertmacro UnselectSection ${SEC_SM}
    !insertmacro UnselectSection ${SEC_UNINST}
${EndIf}
FunctionEnd