I did it before, you want to get a list of all openings, minimize everything, and then repeat this, comparing each program with the one you want to restore, and then restore it. You need to determine which window needs to be restored, I used MainWindowTitle, because I had control over the environment, and therefore I can guarantee that each MainWindowTitle will be unique, you may not have that luxury.
The code I used in the past for this is below, it worked well:
[DllImport("user32.dll")] static extern bool ShowWindow(IntPtr hWnd, int nCmdShow); void SwitchDatabase(string mainWindowTitle) { try { bool launched = false; Process[] processList = Process.GetProcesses(); foreach (Process theProcess in processList) { ShowWindow(theProcess.MainWindowHandle, 2); } foreach (Process theProcess in processList) { if (theProcess.MainWindowTitle.ToUpper().Contains(mainWindowTitle.ToUpper())) { ShowWindow(theProcess.MainWindowHandle, 9); launched = true; } } } catch (Exception ex) { ThrowStandardException(ex); } }
source share