SimonS
SimonS

Reputation: 1973

Is there a way to minimize all windows except one?

I need to Take a screenshot with a script when a process has an error.

is there a way to minimize all windows, except the window of the process that got the error?

I know the way to minimize all:

$shell = new-object -com shell.application
$shell.MinimizeAll()

But is there a way to minimize everything except one window?

Thanks!

Upvotes: 1

Views: 1046

Answers (1)

Esperento57
Esperento57

Reputation: 17462

use API Windows

$Win32ShowWindowAsync = Add-Type –memberDefinition @”  
[DllImport("user32.dll")]  
public static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow);  
“@ -name “Win32ShowWindowAsync” -namespace Win32Functions –passThru 

$titletowindow="TODO.csv - Bloc-notes"

get-process | 
       where mainwindowhandle -ne 0 |  
            %{if ($_.MainWindowTitle -eq $titletowindow) { $Win32ShowWindowAsync::ShowWindowAsync($_.MainWindowHandle, 3) | Out-Null} else { $Win32ShowWindowAsync::ShowWindowAsync($_.MainWindowHandle, 6) | Out-Null} }

Upvotes: 2

Related Questions