C# 杀掉指定exe进程

public static void KillApp(string appName)

{

try

{

if (string.IsNullOrWhiteSpace(appName) || !appName.EndsWith(".exe")) return; //

ProcessStartInfo startInfo = new ProcessStartInfo();

startInfo.FileName = "taskkill.exe";

startInfo.Arguments = string.Format(" /f /t /im {0}", appName);

startInfo.WindowStyle = ProcessWindowStyle.Hidden;

startInfo.Verb = @"runas";

Log.Debug(string.Format("[KillApp] run kill {0} start", appName));

Process process = Process.Start(startInfo);

process.WaitForExit();

Log.Debug(string.Format("[KillApp] run kill {0} end", appName));

}

catch (System.Exception ex)

{

Log.Error(string.Format("[KillApp] run kill {0} failed ", appName), ex);

}

}

相关推荐
MyBFuture20 小时前
C#接口与抽象类:关键区别详解
开发语言·c#·visual studio
曹牧21 小时前
C#:记录日志
服务器·前端·c#
心疼你的一切1 天前
三菱FX5U PLC与C#通信开发指南
开发语言·单片机·c#
czhc11400756631 天前
C# 1221
java·servlet·c#
yong99901 天前
C#实现OPC客户端与S7-1200 PLC的通信
开发语言·网络·算法·c#
先生沉默先1 天前
c#Socket学习,使用Socket创建一个在线聊天,服务端功能实现,(3)
服务器·学习·c#
superman超哥1 天前
仓颉热点代码识别深度解析
开发语言·后端·python·c#·仓颉
Lv11770081 天前
Visual Studio中的接口
ide·笔记·c#·visual studio
阿蒙Amon1 天前
C#每日面试题-类和结构的区别
开发语言·c#
MyBFuture1 天前
索引器实战:对象数组访问技巧及命名空间以及项目文件规范
开发语言·前端·c#·visual studio