【问题标题】:Changing the selection in the components page of NSIS based on the OS on which we are installing根据我们正在安装的操作系统更改 NSIS 组件页面中的选择
【发布时间】:2012-12-04 20:20:50
【问题描述】:

我发现很难更改 nsis 组件页面中的选择。 要求是在安装过程中我得到一个许可协议页面,如果用户同意,那么他/她将点击我同意,用户点击我同意后,我想知道在哪个操作系统上 安装程序正在安装,它可以在 Windows Embedded OS 或 WinXp/Win7 上。 所以如果是 Windows Embedded OS 我想更改安装包,如果不是 Windows Embedded OS 那么安装包会有所不同。

我在我的项目中使用的是 MUI ver1 而不是 MUI2。 请告诉我这是如何实现的。

【问题讨论】:

    标签: nsis


    【解决方案1】:

    要测试运行安装程序的操作系统,您可以使用定义为Winver.nsh 的宏和LogicLib.nsh 提供的宏来进行这样的优雅测试

    ;Dont't forget to include
    !include "LogicLib.nsh"                 # use of various logic statements
    !include "WinVer.nsh"                   # LogicLib extension for OS tests
    

    一个平台测试示例:

    ${if} ${AtLeastWin95}
    ${AndIf} ${AtMostWinME}
        ;here we are on a pre-win2k
        ;do something        
    ${elseIf} ${isWin2008}
    ${orIf} ${AtLeastWin2008R2}
        ;this is post-win7
        ;do other thing
    ${endif}
    

    要在运行时更改要安装的组件,您可以使用来自Sections.nsh 的宏:

    ;if you have
    Section "Sample Database" SecApplicationDB
    ;...
    SectionEnd
    
    ;you can select or un select by code:
    !insertmacro SelectSection ${SecApplicationDB}
    ;or
    !insertmacro UnselectSection ${SecApplicationDB}
    

    【讨论】:

    • 感谢您的反馈。但是在这里我可以通过阅读注册表项来知道我在哪个操作系统上安装设置。我的疑问是如何在 nsis 的组件选择页面中更改安装类型
    • 我发现的一个解决方案是使用 section.nsh 在功能 .onInit 中选择或取消选择组件页面中的复选框。这是正确的解决方案吗?我也尝试过使用 SetCurInstType 但这对我不起作用
    • @DivyPrakash:是的,如果你想改变选定的组件,你可以使用来自sections.nsh的宏,看我的编辑
    • WinVer.nsh 目前不支持测试嵌入位所需的套件掩码...
    • 哎呀,我错过了问题的嵌入部分:(
    【解决方案2】:

    WinVer.nsh 不支持检查 Embedded NT,但您可以自己执行检查:

    !include Sections.nsh
    !include MUI.nsh
    
    !ifndef VER_SUITE_EMBEDDEDNT
    !define VER_SUITE_EMBEDDEDNT 0x00000040
    !endif
    
    !insertmacro MUI_PAGE_LICENSE "${__FILE__}"
    !insertmacro MUI_PAGE_COMPONENTS
    !insertmacro MUI_PAGE_INSTFILES
    !insertmacro MUI_LANGUAGE English
    
    
    Section "Embedded" SID_EMBED
    SectionIn RO
    SectionEnd
    
    Section "Normal" SID_NORMAL
    SectionIn RO
    SectionEnd
    
    Function .onInit
    System::Call '*(i156,&i152)i.r1'
    System::Call 'KERNEL32::GetVersionExA(ir1)'
    System::Call '*$1(&i152,&i2.r2)'
    System::Free $1
    IntOp $2 $2 & ${VER_SUITE_EMBEDDEDNT}
    ${If} $2 <> 0
        !insertmacro SelectSection ${SID_EMBED}
        !insertmacro UnselectSection ${SID_NORMAL}
    ${Else}
        !insertmacro UnselectSection ${SID_EMBED}
        !insertmacro SelectSection ${SID_NORMAL}
    ${EndIf}
    FunctionEnd
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-21
      • 2014-12-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多