
Tengo una solicitud para obtener una captura de pantalla de los íconos del escritorio de los usuarios. Puedo usar Powershell para capturar, pero primero necesito borrar la pantalla, tomar la foto y luego restaurar la pantalla. Las pulsaciones de teclas 'Windows+D' bastarán, pero la tecla de Windows no es una opción para simular en Powershell. ¿Existe otra forma de capturar una captura de pantalla del escritorio?
¡Muchas gracias!
Respuesta1
aquí hay una solución que también toma la captura de pantalla. Lo estoy usando en mis scripts donde necesito hacer una captura de pantalla de algo. ¿Por qué automatizar sólo partes de la tarea, cuando también puedes automatizar todo ;-) verdad?
# 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()
Respuesta2
hay ejemploaquí.
Me encontré con este pequeño consejo mientras exploraba el objeto com shell.application. Tiene otras funciones útiles como desdominimizeall, ventanas en cascada y muchas otras funciones del explorador.
$shell = New-Object -ComObject "Shell.Application"
$shell.minimizeall()
También puede deshacer la minimización de todas las ventanas utilizando el siguiente código.
$shell = New-Object -ComObject "Shell.Application"
$shell.undominimizeall()