有没有办法最小化除一个窗户外的所有窗户?

时间:2016-11-25 11:27:12

标签: powershell

当进程出错时,我需要使用脚本截取屏幕截图。

有没有办法最小化所有窗口,除了得到错误的进程窗口?

我知道最小化所有方法的方法:

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

但除了一个窗口之外,有没有办法减少一切?

谢谢!

1 个答案:

答案 0 :(得分:1)

使用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} }