我在我的主类中得到了这个(该程序是一个修补程序执行程序..):
private void Form1_Load(object sender, EventArgs e)
{
// in the exe.dat is written this(the name of the running exe file): KF2 DSM.exe
string FileName = File.ReadAllText("exe.dat");
// this SHOULD kill the process BUT it doesn't! btw i also treid this: Process.Start("taskkill", "/F /IM " + '"' + FileName + '"');, and still nothing
Process.Start("taskkill", "/F /IM " + FileName);
File.Delete(FileName);
using (var client = new WebClient())
{
client.DownloadFile("https://onedrive.live.com/download?resid=763D7D60E7D1759D!328&authkey=!AArR3IwAehnZ3gc&ithint=file%2cexe", FileName);
while(client.IsBusy)
{
Thread.Sleep(500);
}
}
File.Delete("exe.dat");
Process.Start(FileName);
}
我在代码中为你添加了一些注释。
我尝试了几乎每个语法/代码来杀死一个进程,但没有一个工作!
还有另一种方法来杀死对我有用的过程吗?
答案 0 :(得分:1)
使用Process.GetProcessesByName
和Process.Kill
:
foreach (var process in Process.GetProcessesByName(FileName)) {
process.Kill();
}