允许用户在启动 Windows 服务时输入值 vb.net

发布于 2025-01-01 17:14:43 字数 144 浏览 0 评论 0原文

我需要获取用户输入,以了解他们希望存储我的 Windows 服务生成的文件的位置。

我在想我可以通过在服务的启动事件中读取用户的输入到变量来做到这一点吗?这个变量稍后会在我的 xml 编写器中使用。

这可能吗?或者有更好的方法来做到这一点吗?

I need to get the user input for where they want the files that will be produced by my windows service to be stored.

I was thinking that i could do this by reading in the user's input to a variable in the on start event of my service? this variable is then later used in my xml writer.

Is this possible? Or is there a better way to do this?

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

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

发布评论

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

评论(2

峩卟喜欢 2025-01-08 17:14:43

Windows 服务无法再与桌面交互。他们永远不应该这样做,因为这是一个巨大的安全漏洞。

正确的设计是在安装程序中放置一个自定义对话框,以输入用户输入的值,该值存储在安全的自定义公共属性中。然后使用此属性更新注册表值或 xml 键/值对类型属性。然后重构您的服务类以使用该资源作为配置变化点。

要点是配置设置应该在您的服务尝试启动之前很久就已经设置好。

Windows Services can no longer interact with the desktop. They never should have because this is a huge security hole.

The correct design is to put a custom dialog in your installer to input a value from the user that gets stored in a secure custom public property. Then use this property to update either a registry value or xml key/value pair type attribute. Then refactor your service class to use that resource as the configuration variation point.

The point is the configuration setting should have been set long before your service ever tried to start.

红衣飘飘貌似仙 2025-01-08 17:14:43

如果您想做任何需要 UI 服务的事情,请停止。这不是一个好主意,强烈建议不要这样做。据我所知,人们会创建一个单独的程序来修改Windows服务设置,然后重新启动该服务。现在,如果您只是寻找一种获取非硬编码信息的方法,我只需使用 app.config 文件来存储设置,然后在服务启动时引用它。我也见过其他人使用注册表,但我无法告诉你哪种方法更好。这是一个链接 http://msdn.microsoft。 com/en-us/library/ms379611(v=vs.80).aspx 包含大量有关 My.Settings 的信息,即使它有点过时。创建设置后,您只需在 onstart 事件期间引用它即可。所以你可以这样做:

dim filePath as string = My.Settings.FilePath

HTH

Wade

If you are looking to do anything that requires a UI for a service, stop. This is not a good idea and is highly discouraged. From what I have seen, people will create a seperate program to modifiy the windows service settings and then restart the service. Now, if you are just looking for a way to get information that is not hard-coded, I would just use the app.config file to store the settings and then reference it when the service started. I have seen others use the registry as well, but I can't tell you which way is better. Here is a link http://msdn.microsoft.com/en-us/library/ms379611(v=vs.80).aspx with a lot of information about My.Settings even if it is a bit dated. Once you have a setting created it, you will just need to reference it during the onstart event. So you could do as follows:

dim filePath as string = My.Settings.FilePath

HTH

Wade

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