c#里面如何激活一个外部程序进程并显示在最前
- using System.Diagnostics;
- using System.Runtime.InteropServices;
- [DllImport("user32.dll")]
- public static extern void SwitchToThisWindow(IntPtr hWnd, bool fAltTab);
- private void button3_Click(object sender, EventArgs e)
- {
-
- string pName = "dvdplay";
- Process[] temp = Process.GetProcessesByName(pName);
- if (temp.Length > 0)
- {
- IntPtr handle = temp[0].MainWindowHandle;
- SwitchToThisWindow(handle, true);
- }
- else
- {
- Process.Start(pName + ".exe");
- }
- }
原文地址:https://www.cnblogs.com/ModBus/p/8708052.html