繁体   English   中英

在Windows Service C#中使用值对话框安装

[英]Use value dialog installation in windows service c#

我们正在开发Windows服务以打开特定端口。 现在可以在对话框中为用户自定义此端口。

我想知道捕获此值并传递给服务代码的可能性

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

我尝试在app.config中使用一个值,然后在安装程序中编辑该值:

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是对话框安装中文本框的名称

您将可选的TextBoxes(A)对话框添加到安装项目中,然后用户输入该文本(在文档的EDITA1中):

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

然后在您的自定义操作中,将参数添加如下:

/ port1 = [EDITA1]

在CustomActionData中,然后使用您在安装程序类中显示的那种代码来访问它。

这些可能有用:

.net安装项目:如何传递多个CustomActionData字段

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

这样做的主要问题(由于VS设置项目的工作方式)是您无法在输入时对其进行验证。 VS安装程序项目中的自定义操作会在用户界面和所有内容安装完成后运行,因此,如果您的自定义操作发现不正确,则会使整个安装失败并回滚。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM