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

}

}

相关推荐
XiaoZhenHua9816 小时前
C#工业机器视觉Recipe配方系统设计:多型号、多相机、多工位参数如何统一管理
c#·软件架构·机器视觉·工业自动化·工业软件·recipe
fujisheng66117 小时前
FUI 导航实践:拆开 Layer、History、Coverage 与 Cache 的组合语义
c#·unity3d
淡海水19 小时前
10-05-高级-模式匹配-CSharp如何改变与数据结构的交互方式
数据结构·算法·c#·模式匹配
XiaoZhenHua9819 小时前
C# WinForms + 西门子S7 + SQLite + EPPlus生产数据采集系统架构设计
系统架构·sqlite·c#
Lost of 程序猿20 小时前
船岸数据同步链路实战:SendFlag、单调版本号与断网三天后的续传
后端·c#·asp.net
cjp5602 天前
012.UG二次开发,UG管道服务器与WPF管道通讯,传输JSON数据
c#
jiushidt2 天前
ArcGIS Pro Add‑in 打包流程详解
arcgis·c#·.net·arcgispro
geovindu2 天前
CSharp: Observer Pattern
开发语言·后端·观察者模式·设计模式·c#·.netcore·行为模式
软件黑马王子3 天前
20.Resources资源加载:基本实现
开发语言·前端框架·c#
张人玉3 天前
基于 C# / .NET 8 + Windows Forms + SQLite 的桌面银行业务演示系统——华夏示范银行管理系统
windows·sqlite·c#·.net