日期:2014-05-18 浏览次数:21190 次
[DllImport("user32.dll")] private static extern bool SetForegroundWindow(IntPtr hWnd); [DllImport("user32.dll")] private static extern bool ShowWindow(IntPtr hWnd, int nCmdShow); foreach (System.Diagnostics.Process proc in System.Diagnostics.Process.GetProcesses()) { if (proc.StartInfo.FileName == "xxxx") { IntPtr hWnd = proc.MainWindowHandle; SetForegroundWindow(hWnd); ShowWindow(hWnd , 1); }
------解决方案--------------------
Process process = Process.GetProcessesName("进程名");
process.Id;
------解决方案--------------------
他说的应该是GetProcessesByName,不过,这返回的依然是个数组,
应该是Process[] processs = Process.GetProcessesByName("进程名");
------解决方案--------------------
C#获取进程的主窗口句柄