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()

相關內容