问题
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
.
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.
回答1:
You need to follow these steps:
- Create a Windows Service project. It will create a service project containing
Service1.cs
. - Open
Service1.cs
and right click and choose Add Installer. It will create aProjectInstaller.cs
. - Add a new Setup Project. (If you don't have project template, download and install it from here for VS2013, VS2015 or VS2017)
- Add primary output of the service project to the setup project.
- Go to User Interface window and a new Dialog using TextBoxes (A) template after Installation Folder. (Set visible property of other textboxes than
Edit1
tofalse
.) - Go to Custom Actions window and add a new custom action from primary output of the service project.
- In the Custom Action window, go to this node go to this node Custom Actions → Install → Primary outputfrom WindowsService1 and in Properties window, set the value of
CustomActionData
to/SVCNAME=[EDITA1]
. Open
ProjectInstaller.cs
in your service project and overrideInstall
to setName
orDisplayName
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.
来源:https://stackoverflow.com/questions/49783628/get-user-input-during-installation-using-setup-project-and-use-it-in-installer