Installation NSIS在TeamViewer中安装(便携式模式选项)

Installation NSIS在TeamViewer中安装(便携式模式选项),installation,nsis,Installation,Nsis,我基本上想要的是类似TeamViewer的NSIS安装程序的第一页,包括以下选项: 3个单选按钮:仅运行;为当前用户安装;为所有用户安装(需要使用管理员权限重新启动) 类似于TeamViewer中的许可证标签(即,没有实际的EULA页面,只有页脚中指向该页面的链接) 可以更改文本的按钮,即接受并运行或接受并安装 我不知道如何在UI和控制流方面轻松地做到这一点 此外,如果用户决定为所有用户安装程序,我还需要重新启动安装程序的能力(即,我猜应该有一个可检测的命令行开关,这样如果存在,安装程序将自动采

我基本上想要的是类似TeamViewer的NSIS安装程序的第一页,包括以下选项:

  • 3个单选按钮:仅运行;为当前用户安装;为所有用户安装(需要使用管理员权限重新启动)
  • 类似于TeamViewer中的许可证标签(即,没有实际的EULA页面,只有页脚中指向该页面的链接)
  • 可以更改文本的按钮,即接受并运行或接受并安装
  • 我不知道如何在UI和控制流方面轻松地做到这一点

    此外,如果用户决定为所有用户安装程序,我还需要重新启动安装程序的能力(即,我猜应该有一个可检测的命令行开关,这样如果存在,安装程序将自动采用第三种安装类型)

    所需的示例UI屏幕截图:

    NSIS模板样本将不胜感激

    谢谢

    ...
    RequestExecutionLevel user
    
    !include LogicLib.nsh
    !include nsDialogs.nsh
    !include FileFunc.nsh
    !include MUI2.nsh
    
    Var mode
    Var modeRadioRun
    Var modeRadioInstCU
    Var modeRadioInstLM
    
    Function OnRadioChange
    GetDlgItem $1 $hwndparent 1 ; Find Install/Next button
    ${NSD_GetState} $modeRadioRun $0
    ${If} $0 = ${BST_CHECKED} 
        ${NSD_SetText} $1 "Accept && Run" 
    ${Else}
        ${NSD_SetText} $1 "Accept && Install" 
    ${EndIf}
    FunctionEnd
    
    Function ModePageCreate
    !insertmacro MUI_HEADER_TEXT "Welcome to blah" "blah blah"
    
    ${GetParameters} $0
    ClearErrors
    ${GetOptions} "$0" "/ELEVATEDINSTALL" $0
    ${IfNot} ${Errors}
        UserInfo::GetAccountType
        Pop $0
        ${If} $0 == "Admin"
            StrCpy $mode 1
            Abort ; Skip page and start installing
        ${Else}
            MessageBox mb_iconstop "Admin rights required!"
        ${EndIf}
    ${EndIf}
    
    nsDialogs::Create 1018
    Pop $0
    
    ${NSD_CreateRadioButton} 30u 20u 50% 12u "Run"
    Pop $modeRadioRun
    ${NSD_OnClick} $modeRadioRun OnRadioChange
    
    ${NSD_CreateRadioButton} 30u 40u 50% 12u "Install for current user"
    Pop $modeRadioInstCU
    ${NSD_OnClick} $modeRadioInstCU OnRadioChange
    
    ${NSD_CreateRadioButton} 30u 60u 50% 12u "Install for all users"
    Pop $modeRadioInstLM
    ${NSD_OnClick} $modeRadioInstLM OnRadioChange
    
    ${NSD_CreateLink} 20u -14u 50% 12u "License"
    Pop $0
    ${NSD_OnClick} $0 ShowLicense
    
    ${NSD_Check} $modeRadioRun
    call OnRadioChange ; Trigger button change
    nsDialogs::Show
    FunctionEnd
    
    Function ModePageLeave
    ${NSD_GetState} $modeRadioRun $0
    ${NSD_GetState} $modeRadioInstCU $1
    ${If} $0 = ${BST_CHECKED}
        InitPluginsDir
        SetOutPath $pluginsdir
        File "myapp.exe"
        ExecWait '"$pluginsdir\myapp.exe"'
        SetOutPath $temp ; Don't lock $pluginsdir
        Quit
    ${ElseIf} $1 = ${BST_CHECKED}
        StrCpy $mode 0
    ${Else}
        StrCpy $mode 1
        UserInfo::GetAccountType
        Pop $0
        ${If} $0 != "Admin"
            ExecShell "runas" '"$exepath"' "/ELEVATEDINSTALL"
            Quit
        ${EndIf}
    ${EndIf}
    FunctionEnd
    
    Function ShowLicense
    ExecShell "" "http://example.com/license"
    FunctionEnd
    
    Page Custom ModePageCreate ModePageLeave
    !insertmacro MUI_PAGE_INSTFILES
    !insertmacro MUI_UNPAGE_CONFIRM
    !insertmacro MUI_UNPAGE_INSTFILES
    !insertmacro MUI_LANGUAGE "English"
    
    Section
    ${If} $mode > 0
        SetShellVarContext all
        StrCpy $InstDir "$ProgramFiles\MyApp"
    ${Else}
        SetShellVarContext current
        StrCpy $InstDir "$LocalAppData\Programs\MyApp"
    ${EndIf}
    
    SetOutPath $InstDir
    File myapp.exe
    CreateShortcut "$SMPrograms\MyApp.lnk" "$InstDir\myapp.exe"
    WriteUninstaller "$InstDir\Uninst.exe"
    WriteRegStr SHCTX "Software\Microsoft\Windows\CurrentVersion\Uninstall\MyAppGuid" "UninstallString" '"$InstDir\Uninst.exe"'
    WriteRegStr SHCTX "Software\Microsoft\Windows\CurrentVersion\Uninstall\MyAppGuid" "DisplayName" "MyApp blah blah"
    SectionEnd
    
    Section Uninstall
    ; Todo: Remove files and registry entries (You should write to a .ini in $InstDir so you know if it was a per user or machine install)
    RMDir "$InstDir"
    SectionEnd
    

    您可能需要编辑基本UI,使安装按钮更大(在NSIS\Contrib\UIs中的一个文件上),并在脚本中使用
    ChangeUI
    应用。

    屏幕截图会有所帮助…感谢您指出这一点。。。好了,非常感谢!正是我想要的!作为一个简短的附带问题,您知道如何将NSD_CreateLabel的字体设置为粗体吗?@George:并阅读CreateFont参数的文档…只需创建一个变量并将句柄存储在那里(就像我对单选按钮所做的那样)就可以使用GetDlgItem,您首先必须找到内部对话框(帮助文件中的FindWindow有一个示例)然后用[win]spy[++]或其他工具计算id。如果在“离开”功能中不执行任何操作,它将转到下一页,
    中止
    可用于停止页面更改,因此我不太明白您的要求。。。