C# 进程终止 [英] C# Process Killing

查看:31
本文介绍了C# 进程终止的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在 c# 中编写一个程序,它会启动,杀死一个应该杀死并结束自己的进程exe.

I need to write a program in c# that would just start, kill one processexe that it is supposed to kill and end itself.

我需要杀死的进程是另一个 C# 应用程序,所以它是一个本地用户进程,我知道 exe 的路径.

The process I need to kill is another C# application so it is a local user process and I know the path to the exe.

推荐答案

先在所有进程中搜索你要杀的进程,然后杀掉它.

First search all processes for the process you want to kill, than kill it.

Process[] runningProcesses = Process.GetProcesses();
foreach (Process process in runningProcesses)
{
    // now check the modules of the process
    foreach (ProcessModule module in process.Modules)
    {
        if (module.FileName.Equals("MyProcess.exe"))
        {
            process.Kill();
        }
    }
}

这篇关于C# 进程终止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆