C# 关闭开启进程
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | #region 方法 /// <summary> /// 关闭应用程序 /// </summary> /// <param name="ArrayProcessName">应用程序名之间用‘,’分开</param> private void CloseApp( string ArrayProcessName) { string [] processName = ArrayProcessName.Split( ',' ); foreach ( string appName in processName) { Process[] localByNameApp = Process.GetProcessesByName(appName); //获取程序名的所有进程 if (localByNameApp.Length > 0) { foreach ( var app in localByNameApp) { if (!app.HasExited) { app.Kill(); //关闭进程 } } } } } /// <summary> /// 开启进程 /// </summary> /// <param name="ArrayFolderPath">需要开启进程文件夹的路径,多个路径用‘,’隔开;eg:d:\test,e:\temp</param> private void StartApp( string ArrayFolderPath) { string [] foldersNamePath = ArrayFolderPath.Split( ',' ); foreach ( string folderNamePath in foldersNamePath) { GetFolderApp(folderNamePath); } } /// <summary> /// 递归遍历文件夹内所有的exe文件,此方法可以进一步扩展为其它的后缀文件 /// </summary> /// <param name="folderNamePath">文件夹路径</param> private void GetFolderApp( string folderNamePath) { string [] foldersPath = Directory.GetDirectories(folderNamePath); foreach ( string folderPath in foldersPath) { GetFolderApp(folderPath); } string [] filesPath = Directory.GetFiles(folderNamePath); foreach ( string filePath in filesPath) { FileInfo fileInfo = new FileInfo(filePath); //开启后缀为exe的文件 if (fileInfo.Extension.Equals( ".exe" )) { Process.Start(filePath); } } } #endregion |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Linux系列:如何调试 malloc 的底层源码
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· Apifox不支持离线,Apipost可以!
· 零经验选手,Compose 一天开发一款小游戏!
· 历时 8 年,我冲上开源榜前 8 了!
· Trae 开发工具与使用技巧
· 通过 API 将Deepseek响应流式内容输出到前端