【发布时间】:2015-11-07 03:12:48
【问题描述】:
我在我的主类中得到了这个(程序是一个补丁程序 exe..):
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);
}
我在代码中为你添加了一些注释。
我尝试了几乎所有用于终止进程的语法/代码,但都没有奏效!
还有其他方法可以杀死对我有用的进程吗?
【问题讨论】:
-
您需要转义空格。否则,它会显示为 taskkill 的两个参数。另外,不要为taskkill付出代价。查看 Process 类的其他方法。
-
我之前都试过了
-
在进程名之间使用
\"允许空格,它基本上是创建一个参数而不是多个用空格分隔的参数。 -
Process.Start("taskkill", "/F /IM \"" + FileName+"\"");
标签: c# kill-process