如何控制我的 Win32 服务(即更改其自定义参数、调度等)?

发布于 2025-01-07 14:58:52 字数 149 浏览 6 评论 0原文

我需要在 Delphi XE 中开发一个 Win32 服务,并且我需要找到一种方法如何从同一台机器(或者如果可能的话,最终是 LAN 中的其他机器)控制它。通过控制它,我的意思是更改它由我实现的内部参数,而不是 Windows 服务参数。服务本身不应与桌面交互。您能建议最好的方法吗?

I need to develop a Win32 service in Delphi XE and I need to find a way how to control it from the same machine (or eventually other machines in the LAN if possible). By controlling it I mean changing it's internal parameters implemented by me, not Windows service parameters. The service itself should not interact with the desktop. Could you please advise the best way how to do it?

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

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

发布评论

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

评论(3

独﹏钓一江月 2025-01-14 14:58:52

您可以使用 IPC 方法(如命名管道)与服务进行通信,或者使用 TCP 套接字与服务进行通信。

我用命名管道做到了这一点,它的效果就像一个魅力。

You could use an IPC method like named pipes to communicate with the service or communicate with the service using a TCP socket.

I did it with Named pipes and it works like a charm.

像极了他 2025-01-14 14:58:52

我意识到这是相当低技术的,但实际上您可以将所有设置保留在注册表中,然后前端 GUI 可以写入它们,然后服务可以定期检查名为 HKEY_LOCAL_MACHINE\ 的单个键Software\YourStuff\ConfigurationChangeCounter,如果该值不同,请重新读取配置并应用它(如果需要,可能需要重新启动)。

如果您确实需要做配置以外的事情,那么也许 TCP 套接字会更好,但自己编写一个基于 TCP 的自定义协议处理程序组件并进行调试也需要做很多工作。

但想一想;无论如何,您的服务都需要持久保存并读取配置,为什么不让它使用已有的代码来完成此任务。您可以使用标准 Windows 工具远程连接到计算机并修改其注册表值,并且在大型企业网络中,这种做法已经是标准做法。 Windows 本身的一些服务元素就使用这种方法。

I realize that this is pretty low tech, but you could actually just keep all the settings in the registry, and then the front-end GUI could write to them, and then the service could periodically check a single key called HKEY_LOCAL_MACHINE\Software\YourStuff\ConfigurationChangeCounter and if that value is different, re-read the configuration and apply it (perhaps restarting if necessary).

If you really need to do things other than configuration, then perhaps a TCP socket is lots better, but it's also lots of work to write yourself a custom TCP based protocol handler component and debug that.

But think about it; Your service needs to persist and read configuration anyways, why not just have it use the code it already has to accomplish this task. You can remotely connect to a machine and modify its registry values using standard windows tools, and in large corporate networks, such practices are already standard. Some service elements in Windows itself use this approach.

他不在意 2025-01-14 14:58:52

网内服务器?构建 Web GUI 来控制服务的好、快速(几乎微不足道)的方法。显然,“局域网中的其他机器”(甚至网络)就变成了路由/安全问题,而不是可行性问题。

Intraweb server? Nice, quick, (almost trivial), way to build a web GUI to control a service. Obviously, 'other machines in the LAN', (or even the net), then becomes a matter of routing/security, not feasibility.

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