Csharp启动exe文件

原文

在程序执行中会遇到启动本软件的exe问,或者启用其它的exe文件,已达到执行某些操作的作用。下面是两种最常见的启动exe文件。

1、调用系统dll使用其提供的方法。

引用的dll,

[DllImport("kernel32.dll")]  
  public static extern int WinExec(string exeName, int operType);  

调用,WinExec(@"路径\exe的文件名", 参数);

operType参数如下

0: 隐藏, 并且任务栏也没有最小化图标  
1: 用最近的大小和位置显示, 激活  
2: 最小化, 激活  
3: 最大化, 激活  
4: 用最近的大小和位置显示, 不激活  
5: 同 1  
6: 最小化, 不激活  
7: 同 3  
8: 同 3  
9: 同 1  
10: 同 1  

最常见的ProcessStartInfo启动

ProcessStartInfo info = new ProcessStartInfo();             
info.FileName = @"路径\exe的文件名";              
info.Arguments = "";              
info.WindowStyle = ProcessWindowStyle.Minimized;             
Process pro = Process.Start(info);              
pro.WaitForExit();  

3、结束启动的exe的进程

Process[] allProgresse = System.Diagnostics.Process.GetProcessesByName("exe的进程名");  
 foreach (Process closeProgress in allProgresse)  
{  
   if (closeProgress.ProcessName.Equals("exe的进程名"))  
         {  
                closeProgress.Kill();  
                 closeProgress.WaitForExit();  
                  break;  
           }  
 }  
原文地址:https://www.cnblogs.com/zhanhengzong/p/3035295.html