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, 계단식 창 및 기타 여러 탐색기 기능과 같은 기타 유용한 기능이 있습니다.

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

아래 코드를 사용하여 모든 창 최소화를 취소할 수도 있습니다.

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

관련 정보