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

}

}

相关推荐
View121381 小时前
在 .NET 中使用 Moonshot Kimi + AgentFramework:从 SDK 到 Agent 的完整实践
c#·agent·kimi
FlDmr4i282 小时前
.NET 10 & C# 14 New Features 新增功能介绍-扩展成员Extension Members
开发语言·c#·.net
QJtDK1R5a4 小时前
C# 14 中的新增功能
开发语言·c#
雨浓YN6 小时前
WebApi 通讯-DeepSeek API调用文档
c#
yuan199977 小时前
C# 断点续传下载文件工具设计与实现
开发语言·c#
雨浓YN9 小时前
WebApi 通讯-自写Demo技术文档
c#
唐青枫9 小时前
C#.NET TPL Dataflow 深入解析:数据流管道、背压控制与实战取舍
c#·.net
喵叔哟10 小时前
4.【.NET10 实战--孢子记账--产品智能化】--C# 14 新语法特性详解与实战应用
java·c#·.net
Khsc434ka10 小时前
.NET 10 与智能体时代的架构演进:以 File-Based Apps 为核心的 C# 生态重塑
架构·c#·.net
jackylzh10 小时前
C# 中 LINQ 和 Lambda 表达式的 基本用法
c#