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);

}

}

相关推荐
用户298698530142 分钟前
C#:三行代码,给 Word 文档的文本框“一键清空”
后端·c#·.net
唐青枫6 小时前
C#.NET Expression Tree 深入解析:表达式树、动态查询与运行时代码生成
c#·.net
程序设计实验室1 天前
C# 扩展方法只会写 this 吗?C# 14 新语法直接把扩展方法玩出了花
c#
唐青枫1 天前
C#.NET SignalR 深入解析:实时通信、Hub 与连接管理实战
c#·.net
唐宋元明清21881 天前
.NET Win32磁盘动态卷/跨区卷触发“函数不正确”问题排查
windows·c#·存储
hez20102 天前
Satori GC:同时做到高吞吐、低延时和低内存占用
c#·.net·.net core·gc·clr
唐青枫2 天前
C#.NET Channel 深入解析:高性能异步生产者消费者模型实战
c#·.net
小峥降临3 天前
Rokid UXR 的手势追踪虚拟中更真实的手实战开发【含 工程源码 和 最终完成APK】
c#
晨星shine7 天前
GC、Dispose、Unmanaged Resource 和 Managed Resource
后端·c#
用户298698530147 天前
.NET 文档自动化:Spire.Doc 设置奇偶页页眉/页脚的最佳实践
后端·c#·.net