【问题标题】:How to pass command line arguments when run after install with electron-builder NSIS installer使用 electron-builder NSIS 安装程序安装后运行时如何传递命令行参数
【发布时间】:2018-08-22 10:16:18
【问题描述】:

使用 electron-builder NSIS 安装程序,我们能够创建一个可执行安装程序,它会在安装完成后立即启动已安装的电子应用程序。我的问题是有没有办法在第一次启动时将安装程序本身启动时使用的任何命令行参数传递给已安装的应用程序?

我看到了一些 NSIS 自定义脚本,它们建议可以使用Exec 启动可执行文件,并且可以使用GetParameters 检索安装程序参数。这是推荐的方向,还是在 electron-builder 或 NSIS 中有一些配置选项?

编辑:

这是一个可能的解决方案:

  • nsis.runAfterFinishelectron-builder 选项设置为false(默认为true);
  • 实现 customInstall 事件处理程序以自定义正常的电子生成器提供的模板:

    !macro StartAppWithParameters
        Var /GLOBAL startAppWithParametersArgs
        ${if} ${isUpdated}
            StrCpy $startAppWithParametersArgs "--updated"
        ${else}
            StrCpy $startAppWithParametersArgs ""
        ${endif}
        ${StdUtils.GetAllParameters} $R0 0
        ${StdUtils.ExecShellAsUser} $0 "$launchLink" "open" '$startAppWithParametersArgs $R0'
    !macroend
    
    !macro customInstall
        HideWindow
        !insertmacro StartAppWithParameters
    !macroend
    

详情在electron-builder NSIS configurationelectron-builder NSIS template

谢谢!

【问题讨论】:

    标签: nsis electron-builder


    【解决方案1】:

    是的,您可以使用 ExecGetParameters 手动完成:

    !include "FileFunc.nsh"
    !include "MUI2.nsh"
    
    !macro RunWithInstallersParameters app
    Push "${app}"
    Call RunWithInstallersParameters
    !macroend
    Function RunWithInstallersParameters
    Exch $0
    Push $1
    ${GetParameters} $1
    Exec '"$0" $1'
    Pop $1
    Pop $0
    FunctionEnd
    
    !insertmacro MUI_PAGE_DIRECTORY
    !insertmacro MUI_PAGE_INSTFILES
    !define MUI_FINISHPAGE_RUN
    !define MUI_FINISHPAGE_RUN_FUNCTION MyFinishRun
    !insertmacro MUI_PAGE_FINISH
    !insertmacro MUI_LANGUAGE English
    
    Function MyFinishRun
    !insertmacro RunWithInstallersParameters "$sysdir\Calc.exe"
    FunctionEnd
    
    Section
    SetOutPath $InstDir
    File "blahblah"
    !insertmacro RunWithInstallersParameters "$windir\Notepad.exe"
    SectionEnd
    

    MUI Finish 页面也支持直接指定参数的方式,但由于我们在编译时不知道参数,所以我们必须使用变量:

    !include "FileFunc.nsh"
    !include "MUI2.nsh"
    
    !insertmacro MUI_PAGE_DIRECTORY
    !insertmacro MUI_PAGE_INSTFILES
    !define MUI_FINISHPAGE_RUN "$windir\Notepad.exe"
    !define MUI_FINISHPAGE_RUN_PARAMETERS $1 ; Initialized by our MUI_PAGE_CUSTOMFUNCTION_SHOW function
    !define MUI_PAGE_CUSTOMFUNCTION_SHOW InitFinishPage
    !insertmacro MUI_PAGE_FINISH
    !insertmacro MUI_LANGUAGE English
    
    Function InitFinishPage
    ${GetParameters} $1
    FunctionEnd
    

    我对electron-builder一无所知,但我认为您可以通过某种方式自定义 NSIS 脚本。

    【讨论】:

      猜你喜欢
      • 2019-07-26
      • 2020-05-26
      • 2020-03-26
      • 2011-04-01
      • 2020-07-04
      • 1970-01-01
      • 2019-03-28
      • 1970-01-01
      • 2011-06-03
      相关资源
      最近更新 更多