将参数发送到 Windows 服务安装程序 Visual Studio

发布于 2024-12-25 19:01:17 字数 234 浏览 7 评论 0原文

我是 C# 新手,刚刚创建了一个在事件日志中写入一些日志的 Windows 服务。为了安装它,我创建了一个 Visual Studio 安装项目,一切正常。

我希望该服务有一个可以在安装时创建的配置文件。所以它在安装时应该接收一些参数,例如: -写入数据库或事件日志 -输入文件夹路径(它使用从中读取数据的输入文件夹) -ETC。

我知道参数是由服务在 OnStart 方法中接收的,我只是不知道如何将参数发送到该方法。

I am new to C# and I just created a Windows Service that writes some logs in the event log. In order to install it I created a Visual Studio Setup Project and it all works.

I would like this service to have a configuration file that may be created when installing it. So it should receive some parameters when being installed, like:
-writes to database or event log
-input folder path (it uses an input folder where it reads data from)
-etc.

I know the parameters are received by the service in the OnStart method, I just don't know how to send the parameters to this method.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

耀眼的星火 2025-01-01 19:01:17

沿着 DJ Kraze 的评论。我将使用应用程序配置 http://msdn.microsoft.com/en-us /library/1xtk877y.aspx。然后创建一个安装项目(创建 MSI)以在安装时设置配置参数。 http://raquila.com/software/configure- app-config-application-settings-during-msi-install/

Along the lines of DJ Kraze's comment. I would use an application config http://msdn.microsoft.com/en-us/library/1xtk877y.aspx. Then create a setup project (creates the MSI) to set the configuration parameters at install time. http://raquila.com/software/configure-app-config-application-settings-during-msi-install/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文