PowerShell - Windows-D をシミュレートして画面をクリアして復元する

PowerShell - Windows-D をシミュレートして画面をクリアして復元する

ユーザーのデスクトップ アイコンのスクリーンショットを取得したいというリクエストがあります。Powershell を使用してキャプチャできますが、最初に画面をクリアし、ショットを撮り、その後画面を復元する必要があります。キーストローク「Windows+D」で実行できますが、Windows キーは Powershell でシミュレートするオプションではありません。デスクトップのスクリーンショットをキャプチャする別の方法はありますか?

どうもありがとう!

答え1

スクリーンショットも撮れるソリューションがここにあります。私は、スクリーンショットを撮る必要があるスクリプトでこれを使用しています。すべてを自動化できるのに、なぜタスクの一部だけを自動化するのでしょうか ;-) そうですよね?

# Take Screenshot function - reads width and height from WMI, saves in outfile path
function Take-Screenshot([string]$outfile) 
{
    [int]$PrtScrnWidth = (gwmi Win32_VideoController).CurrentHorizontalResolution
    [int]$PrtScrnHeight = (gwmi Win32_VideoController).CurrentVerticalResolution
    $bounds = [Drawing.Rectangle]::FromLTRB(0, 0, $PrtScrnWidth, $PrtScrnHeight)
    $bmp = New-Object Drawing.Bitmap $bounds.width, $bounds.height
    $graphics = [Drawing.Graphics]::FromImage($bmp)
    $graphics.CopyFromScreen($bounds.Location, [Drawing.Point]::Empty, $bounds.size)
    $bmp.Save($outfile)
    $graphics.Dispose()
    $bmp.Dispose()
}

# Minimize all the Windows
$shell = New-Object -ComObject "Shell.Application"
$shell.minimizeall()

#sleep to make sure not to screenshot while everything is still minimizing
sleep -s 2

# Take the Screenshot - choose your outfile path
Take-Screenshot -outfile C:\Batch\test4.png

# get your screen back
$shell.undominimizeall()

答え2

例がありますここ

shell.application com オブジェクトを調べているときに、この小さなヒントを見つけました。このオブジェクトには、undominimizeall、cascade windows、その他多くのエクスプローラー関数など、他にも便利な関数があります。

$shell = New-Object -ComObject "Shell.Application"
$shell.minimizeall()

以下のコードを使用して、すべてのウィンドウの最小化を元に戻すこともできます。

$shell = New-Object -ComObject "Shell.Application"
$shell.undominimizeall()

関連情報