2013-09-24 117 views
1

我想爲應用程序創建雙安裝程序,將其安裝爲便攜式或普通版本。NSIS - 需要管理員權限

對於便攜版本,我不想要求管理員權限。對於正常版本,我需要它們將應用程序添加到startmenu和其他東西。

開始實際安裝時有沒有辦法提升管理員權限?也許有一個插件?類似於部分內部的「RequestExecutionLevel admin」。

謝謝!

回答

1

RequestExecutionLevel highest將強制管理員組的成員提升,而普通用戶可以在沒有UAC交互的情況下運行它。因爲這樣做是棘手的,UAC在某些情況下破這個例子不提高對你和它需要更多的代碼來正確地做到這一點...

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 
+0

選擇「最高」將迫使它來安裝作爲管理員,如果用戶是admin。我認爲最初的問題需要管理員在安裝時可以選擇是否需要系統安裝。 – teeks99

+0

最高將允許管理員用戶選擇。他們將被迫使用UAC升級,但非管理員安裝應該正常工作。 – Anders