c# 启动关闭进程
2012-12-25 08:55
363 查看
摘要: 本文主要内容:通过代码的方式关闭进程。 以前关闭进程的方式,通常采用bat文件的方式。现在通过采用另外一种方式关闭进程。关闭进程主要思路:遍历所有进程,根据进程名称,找出需要关闭的进程。开启进程主要思路: ...
转载:http://www.189works.com/article-39495-1.html
本文主要内容:通过代码的方式关闭进程。 以前关闭进程的方式,通常采用bat文件的方式。现在通过采用另外一种方式关闭进程。 关闭进程主要思路:遍历所有进程,根据进程名称,找出需要关闭的进程。 开启进程主要思路:通过递归的方式找出文件夹中所有的exe文件,并且开启。 其主要代码如下: 1 #region 方法 2 ///<summary> 3 /// 关闭应用程序 4 ///</summary> 5 ///<param name="ArrayProcessName">应用程序名之间用‘,’分开</param> 6 private void CloseApp(string ArrayProcessName) 7 { 8 string[] processName = ArrayProcessName.Split(','); 9 foreach (string appName in processName) 10 { 11 Process[] localByNameApp = Process.GetProcessesByName(appName);//获取程序名的所有进程 12 if (localByNameApp.Length > 0) 13 { 14 foreach (var app in localByNameApp) 15 { 16 if (!app.HasExited) 17 { 18 app.Kill();//关闭进程 19 } 20 } 21 } 22 } 23 } 24 25 ///<summary> 26 /// 开启进程 27 ///</summary> 28 ///<param name="ArrayFolderPath">需要开启进程文件夹的路径,多个路径用‘,’隔开;eg:d:\test,e:\temp</param> 29 private void StartApp(string ArrayFolderPath) 30 { 31 string[] foldersNamePath = ArrayFolderPath.Split(','); 32 foreach (string folderNamePath in foldersNamePath) 33 { 34 GetFolderApp(folderNamePath); 35 } 36 } 37 38 ///<summary> 39 /// 递归遍历文件夹内所有的exe文件,此方法可以进一步扩展为其它的后缀文件 40 ///</summary> 41 ///<param name="folderNamePath">文件夹路径</param> 42 private void GetFolderApp(string folderNamePath) 43 { 44 string[] foldersPath = Directory.GetDirectories(folderNamePath); 45 foreach (string folderPath in foldersPath) 46 { 47 GetFolderApp(folderPath); 48 } 49 50 string[] filesPath = Directory.GetFiles(folderNamePath); 51 foreach (string filePath in filesPath) 52 { 53 FileInfo fileInfo = new FileInfo(filePath); 54 55 //开启后缀为exe的文件 56 if (fileInfo.Extension.Equals(".exe")) 57 { 58 Process.Start(filePath); 59 } 60 } 61 62 } 63 #endregion winform的界面如下: |
相关文章推荐
- C# 进程启动与关闭
- C# 进程启动与关闭
- c# 启动关闭进程
- c#启动关闭进程
- C# 进程启动与关闭
- C# 启动关闭.exe进程(转)
- C# 启动线程后,关闭form窗体,进程未关闭问题
- C#实现启动,关闭与查找进程的方法
- c# 启动关闭进程
- C#启动和关闭进程操作
- c# 启动关闭进程
- Linux下Tomcat的启动、关闭、杀死进程以及查看日志
- Linux下Tomcat的启动、关闭、杀死进程以及查看日志
- C#实现进程管理的启动和停止实例
- C# 启动进程和杀死进程
- 使用windows钩子捕获进程的启动和关闭消息
- C# 关闭窗体立即停止进程
- c# 关闭其他程序窗口/进程
- C# 关闭 Excel进程
- IronPython调用C#启动外部进程