【问题标题】:create c# installer - ask for shortcut parameters创建 C# 安装程序 - 询问快捷方式参数
【发布时间】:2016-03-30 00:45:24
【问题描述】:

是否可以为要求将参数传递给快捷方式的简单 .exe(控制台应用程序)创建安装程序?

我的应用程序需要有“源路径”和“目标路径”以及第三个可选参数...

我真的不知道我要在 Google 中寻找什么(英文单词)。

另外,我需要把这个快捷方式放在启动中,可以吗?

我查看了 nsis 和高级安装程序,他们似乎不允许该选项。

编辑

我想要的是,在安装过程中,向用户询问参数是什么。根据哪个用户,参数会有所不同。

我也在寻找免费的东西,因为我可能永远不会再使用它了......

【问题讨论】:

  • 是的,使用 Visual Studio 安装程序项目。
  • Inno Setup 是迄今为止我发现的最好的免费安装软件:jrsoftware.org/isdl.php 同样,为了将参数传递给应用程序,只需在 program.cs(用于 winform)中使用 args[]控制台应用程序的 main

标签: c# console-application nsis advanced-installer


【解决方案1】:

您可以使用nsDialogs plug-in 在 NSIS 中创建自定义对话框:

OutFile "mysetup.exe"
RequestExecutionLevel admin
InstallDir "$ProgramFiles\MyApp"

Page Custom CustomShortcutPageCreate CustomShortcutLeave
Page InstFiles

!include nsDialogs.nsh

Var ShortcutParameter

Function CustomShortcutPageCreate
    nsDialogs::Create 1018
    Pop $0
    ${NSD_CreateLabel} 0 10u 100% 12u "Please enter the shortcut parameter"
    Pop $0
    ${NSD_CreateText} 0 30u 100% 12u ""
    Pop $9
    nsDialogs::Show
FunctionEnd

Function CustomShortcutLeave
    ${NSD_GetText} $9 $ShortcutParameter
FunctionEnd

Section
    SetOutPath $InstDir
    File MyApp.exe
SectionEnd

Section
    CreateDirectory "$SMStartup" ; Make sure the folder exists just in case the user has "cleaned" their start menu
    CreateShortcut "$SMStartup\MyApp.lnk" "$InstDir\MyApp.exe" $ShortcutParameter
SectionEnd

【讨论】:

    【解决方案2】:

    我想您正在使用 C# 和 Microsoft Visual Studio。 在这种情况下,您可以同时使用 NSIS 和 Inno Setup 来创建安装程序。

    使用带有 Visual & Installer 扩展 (https://visualstudiogallery.msdn.microsoft.com/5e57fe9a-ae5d-4740-a1c3-7a8e278e105b) 的任何 Visual Studio 版本

    上面提到的 NSIS 示例将在其中完美运行(也类似 Inno Setup 代码)。

    【讨论】:

      【解决方案3】:

      使用永久免费的Simple project type from Advanced Installer,您可以在 2 分钟内创建一个shortcut with custom arguments

      只需在编辑快捷方式属性的对话框中可见的参数字段中设置所需的参数,如下所示:

      我不明白你想如何自定义第三个参数。能否提供更多细节,一个例子?

      Arguments 字段中,您可以设置类似 [MY_CUSTOM_ARG] 的属性,并在安装时将属性的值解析为自定义值(当然,之前快捷方式已安装)。

      编辑使用高级安装程序的免费/简单版,您无法自定义对话框,您只能使用对话框页面中提供的预定义对话框之一。

      对话框编辑器作为高级安装程序商业企业版的一项功能提供。

      免费的开源替代方案是使用 Wix 工具集,但是,如果您从未使用过它,学习曲线可能会很陡峭。

      【讨论】:

      • 我想要的是,在安装过程中,向用户询问参数是什么。根据哪个用户,参数会有所不同。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多