c#啟動EXE文件的方法實例
更新時間:2013年04月22日 15:16:03 作者:
在程序執(zhí)行中會遇到啟動本軟件的exe問,或者啟用其它的exe文件,已達到執(zhí)行某些操作的作用。下面是兩種最常見的啟動exe文件。
1、調用系統(tǒng)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;
}
}