0

We are develop a windows service for open a specific port. Now this port can be custom for the user during the installation in a dialog.

I want know a possibility of capture this value and pass to the code of the service

            if (myServer == null)
            {
                int port=  int.Parse(ConfigurationManager.AppSettings["port1"]);
                myServer = new NHttp.HttpServer
                {
                    EndPoint = new System.Net.IPEndPoint(0, port)
                };
            }
            myServer.Start();

I try using a value in app.config and editing this value in the installer:

public override void Install(System.Collections.IDictionary stateSaver)
    {
        string portServer= this.Context.Parameters["CTPUERTO"];
        System.Configuration.ConfigurationManager.AppSettings.Set("port1", portServer);
        base.Install(stateSaver);            
    }

CTPUERTO is the name of the textbox in the dialog install

araad1992
  • 104
  • 10

1 Answers1

0

You add the optional TextBoxes(A) dialog to your setup project and the user enters that text (in EDITA1 in the docs):

https://msdn.microsoft.com/en-us/library/e04k6f53(v=vs.100).aspx

Then in your custom action you'd add the parameter with something like:

/port1=[EDITA1]

in CustomActionData, then access it using the kind of code you showed, in an installer class.

These might be useful:

.net Setup Project: How to pass multiple CustomActionData fields

https://www.codeproject.com/Articles/12780/A-Setup-and-Deployment-project-that-passes-paramet

The main issue with this (because of the way VS setup projects work) is that you cannot validate it at the time it's entered. Custom actions in VS setup projects run after the UI and after everything is installed, so if your custom finds it's incorrect then you fail the whole install and roll back.

PhilDW
  • 20,260
  • 1
  • 18
  • 28