获取Windows服务的PID [英] Get the PID of a Windows service
本文介绍了获取Windows服务的PID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
任何人都可以帮助我了解如何获得Windows服务的PID?
我需要的PID,以运行以下命令:
的Process.Start(新的ProcessStartInfo
{
文件名=cmd.exe的,
CreateNoWindow = TRUE,
UseShellExecute =假,
参数=的String.Format(/ C TASKKILL / PID {0} / F,pidnumber)
});
解决方案
假设你知道EXE的服务使用的和名称恰好有其中之一:
INT PROCID = Process.GetProcessesByName(yourservice.exe)[0] .ID;
方法 Process.GetProcessesByName(yourservice.exe)
返回进程与您指定名称的Array,所以如果你不知道有多少yourservice.exe
运行,同时放,你可能需要一个foreach循环。
Could anyone help me to know how to get the PID of a Windows service?
I need to get the PID in order to run the following command:
Process.Start(new ProcessStartInfo
{
Filename = "cmd.exe",
CreateNoWindow = true,
UseShellExecute = false,
Arguments = string.Format("/c taskkill /pid {0} /f", pidnumber)
});
解决方案
Assuming you know the name of the EXE the service uses and there is exactly one of them:
int procID = Process.GetProcessesByName("yourservice.exe")[0].Id;
The method Process.GetProcessesByName("yourservice.exe")
returns an Array of Processes with your specified name, so in case you don't know how much of "yourservice.exe"
runs simultaniously you might need a foreach loop.
这篇关于获取Windows服务的PID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文