使用安装项目在安装过程中获取用户输入并在安装程序中使用它 [英] Get user input during installation using setup project and use it in installer

查看:60
本文介绍了使用安装项目在安装过程中获取用户输入并在安装程序中使用它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个安装程序来安装 Windows 服务.安装程序应要求用户为服务命名.因此,我在安装程序中使用 TextBox 创建了一个自定义 UI.

I have created an installer to install a windows service. Installer should ask user to name the service. Hence, I have created a custom UI in the installer with TextBox.

当用户运行 setup.exe 文件时,安装开始并显示自定义 UI.用户添加了 Windows 服务的名称,但是我应该如何在安装过程中将 ServiceName 作为用户输入并将默认服务名称设置为用户在安装过程中在该自定义 UI 中提供的服务名称.

When user runs the setup.exe file, installation starts and the custom UI shows up. User adds the name for the windows service but how shall I take the ServiceName as user input during installation and set default service name into service name provided by user during installation in that custom UI.

推荐答案

您需要按照以下步骤操作:

You need to follow these steps:

  1. 创建一个 Windows 服务项目.它将创建一个包含 Service1.cs 的服务项目.
  2. 打开Service1.cs 并右键单击并选择添加安装程序.它将创建一个 ProjectInstaller.cs.
  3. 添加一个新的设置项目.(如果您没有项目模板,请从此处下载并安装 VS2013VS2015VS2017)
  4. 将服务项目的主要输出添加到设置项目.
  5. 转到用户界面窗口,并在安装文件夹之后使用TextBoxes (A)模板创建一个新对话框.(将除 Edit1 之外的其他文本框的可见属性设置为 false.)
  6. 转到自定义操作窗口并从服务项目的主要输出添加一个新的自定义操作.
  7. 自定义操作窗口中,转到此节点转到此节点自定义操作安装WindowsService1的主要输出 并在 Properties 窗口中,将 CustomActionData 的值设置为 /SVCNAME=.
  8. 在您的服务项目中打开 ProjectInstaller.cs 并覆盖 Install 以设置 NameDisplayName服务:

  1. Create a Windows Service project. It will create a service project containing Service1.cs.
  2. Open Service1.cs and right click and choose Add Installer. It will create a ProjectInstaller.cs.
  3. Add a new Setup Project. (If you don't have project template, download and install it from here for VS2013, VS2015 or VS2017)
  4. Add primary output of the service project to the setup project.
  5. Go to User Interface window and a new Dialog using TextBoxes (A) template after Installation Folder. (Set visible property of other textboxes than Edit1 to false.)
  6. Go to Custom Actions window and add a new custom action from primary output of the service project.
  7. In the Custom Action window, go to this node go to this node Custom ActionsInstallPrimary outputfrom WindowsService1 and in Properties window, set the value of CustomActionData to /SVCNAME=.
  8. Open ProjectInstaller.cs in your service project and override Install to set Name or DisplayName of the service:

public override void Install(IDictionary stateSaver)
{
    string value = Context.Parameters["SVCNAME"];
    this.serviceInstaller1.DisplayName = value;
    base.Install(stateSaver);
}

然后构建您的项目并安装服务.

Then build your projects and install the service.

这篇关于使用安装项目在安装过程中获取用户输入并在安装程序中使用它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆