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

}

}

相关推荐
唐青枫1 天前
别再乱用 StartNew:C#.NET TaskFactory 任务调度实战详解
c#·.net
Artech2 天前
[MAF预定义的AIContextProvider-03]ChatHistoryMemoryProvider——赋予Agent从经验中学习的能力
ai·c#·agent·memory·maf
Scout-leaf3 天前
C#摸鱼实录——IoC与DI案例详解
c#
咕白m6253 天前
使用 C# 在 Excel 中应用多种字体样式
后端·c#
Artech4 天前
[MAF预定义的AIContextProvider-02]AgentSkillsProvider——将Agent Skills引入MAF
ai·c#·agent·agent skills·maf
2601_962072554 天前
李梦娇常识4600问|题库|打印版
sql·华为od·华为·c#·华为云·.net·harmonyos
m0_547486664 天前
《C#语言程序设计与实践》 全套PPT课件
c语言·c#·c语言程序设计
叶帆4 天前
【YFIOs】用C#开发硬件之设备上云
开发语言·unity·c#
IT方大同5 天前
(嵌入式操作系统)信号量
嵌入式硬件·c#
z落落5 天前
C# FileStream文件流读取文件
开发语言·c#