我正在搜索如何在C#中做到这一点,如下所示:
foreach (Process proc in Process.GetProcessesByName("cheatengine-x86_64"))
{
proc.Kill();
}我正在使用这个语句,但是程序有不同的版本,像是cheatengine或cheatengine-x86,我想关闭其中的任何一个,从'cheat‘开始,或者仅仅是'cheate',只是为了避免较旧的版本。
发布于 2013-02-01 02:07:11
System.Diagnostics.Process.GetProcesses()
.Where(x => x.ProcessName.StartsWith("cheate", StringComparison.OrdinalIgnoreCase))
.ToList()
.ForEach(x => x.Kill());发布于 2013-02-01 02:01:51
您可以遍历每个进程名,然后将其与regexp匹配,如果匹配则终止它。
Regex regex = new Regex(@"cheate.*");
foreach (Process p in Process.GetProcesses(".")){
if(regex.Matches(p.ProcessName))
p.Kill();
}就像这样。
这样做的好处是,您可以终止以特定正则表达式开头或结尾的任何进程。
发布于 2013-02-01 02:07:04
改编自:http://www.howtogeek.com/howto/programming/get-a-list-of-running-processes-in-c/
using System.Diagnostics;
Process[] processlist = Process.GetProcesses();
foreach(Process theprocess in processlist)
{
if(theprocess.ProcessName.StartsWith("cheat");
theprocess.Kill();
}这只是一个粗略的想法,你可以使用任何你想要匹配过程的方法。我推荐一些忽略大小写的东西,但我会非常谨慎地对待误报。如果你的程序关闭了一些不该关闭的东西,我会很不高兴的。
https://stackoverflow.com/questions/14632162
复制相似问题