powershell - simula o Windows-D para limpar e restaurar a tela

powershell - simula o Windows-D para limpar e restaurar a tela

Tenho uma solicitação para obter uma captura de tela dos ícones da área de trabalho dos usuários. Posso usar o Powershell para capturar, mas primeiro preciso limpar a tela, tirar a foto e depois restaurar a tela. As teclas 'Windows + D' farão isso, mas a tecla Windows não é uma opção para simular no Powershell. Existe outra maneira de capturar uma captura de tela da área de trabalho?

Muito obrigado!

Responder1

aqui está uma solução que também tira a captura de tela. Estou usando isso em meus scripts onde preciso capturar algo. por que automatizar apenas partes da tarefa, quando você também pode automatizar tudo ;-) certo?

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

Responder2

Há exemploaqui.

Me deparei com esta pequena dica enquanto explorava o objeto shell.application com. Possui outras funções úteis como undominimizeall, janelas em cascata e muitas outras funções do explorador.

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

Você também pode desfazer a minimização de todas as janelas usando o código abaixo.

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

informação relacionada