如何从 ServiceController 确定 Windows.Diagnostics.Process
这是我的第一篇文章,所以让我首先说你好!
我正在编写一个 Windows 服务来监视同一服务器上许多其他 Windows 服务的运行状态。我想扩展应用程序以打印服务的一些内存统计信息,但我无法弄清楚如何从特定的 ServiceController 对象映射到其关联的 Diagnostics.Process 对象,我认为我需要确定内存状态。
我找到了如何从 ServiceController 映射到原始映像名称,但我正在监视的许多服务是从同一个映像启动的,因此这不足以确定进程。
有谁知道如何从给定的 ServiceController 获取 Process 对象?也许通过确定服务的 PID 来实现?或者还有人有其他解决方法来解决这个问题吗?
非常感谢,亚历克斯
This is my first post, so let me start by saying HELLO!
I am writing a windows service to monitor the running state of a number of other windows services on the same server. I'd like to extend the application to also print some of the memory statistics of the services, but I'm having trouble working out how to map from a particular ServiceController object to its associated Diagnostics.Process object, which I think I need to determine the memory state.
I found out how to map from a ServiceController to the original image name, but a number of the services I am monitoring are started from the same image, so this won't be enough to determine the Process.
Does anyone know how to get a Process object from a given ServiceController? Perhaps by determining the PID of a service? Or else does anyone have another workaround for this problem?
Many thanks, Alex
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在这种情况下,System.Management 应该适合您。这是一个帮助您入门的示例:
System.Management should work for you in this case. Here's a sample to get you started: