在程序執行中會遇到啟動本軟件的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
2、最常見的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;
- }
- }