Created
September 9, 2022 17:37
-
-
Save cleytonferrari/f716ded1065ca96933f742b13c064956 to your computer and use it in GitHub Desktop.
Salva print via powershell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Salva print via Powershell | |
#Maiores informações https://stackoverflow.com/questions/2969321/how-can-i-do-a-screen-capture-in-windows-powershell/2970339#2970339 | |
#Para usar: > .\print.ps1 "C:\Users\Cleyton Ferrari\Downloads\" | |
Param( | |
[string]$path | |
) | |
[Reflection.Assembly]::LoadWithPartialName("System.Drawing") | |
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing") | |
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") | |
function screenshot($path) | |
{ | |
$width = 0; | |
$height = 0; | |
$workingAreaX = 0; | |
$workingAreaY = 0; | |
$fileName = get-date -uformat "\%d-%m-%Y_%H-%M-%S.png"; | |
$screen = [System.Windows.Forms.Screen]::AllScreens; | |
foreach ($item in $screen) | |
{ | |
if($workingAreaX -gt $item.WorkingArea.X) | |
{ | |
$workingAreaX = $item.WorkingArea.X; | |
} | |
if($workingAreaY -gt $item.WorkingArea.Y) | |
{ | |
$workingAreaY = $item.WorkingArea.Y; | |
} | |
$width = $width + $item.Bounds.Width; | |
if($item.Bounds.Height -gt $height) | |
{ | |
$height = $item.Bounds.Height; | |
} | |
} | |
$bounds = [Drawing.Rectangle]::FromLTRB($workingAreaX, $workingAreaY, $width, $height); | |
$bmp = New-Object Drawing.Bitmap $width, $height; | |
$graphics = [Drawing.Graphics]::FromImage($bmp); | |
$graphics.CopyFromScreen($bounds.Location, [Drawing.Point]::Empty, $bounds.size); | |
$bmp.Save($path+$fileName); | |
$graphics.Dispose(); | |
$bmp.Dispose(); | |
} | |
screenshot $path |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment