Advertisement
jsmth90

screenshot

Mar 25th, 2019
17,279
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ([Reflection.Assembly]::LoadWithPartialName("System.Drawing")) | Out-Null
  2. [void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")
  3. [void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
  4. function screenshot($path)
  5. {
  6.     $width = 0;
  7.     $height = 0;
  8.     $workingAreaX = 0;
  9.     $workingAreaY = 0;
  10.     $screen = [System.Windows.Forms.Screen]::AllScreens;
  11.     foreach ($item in $screen)
  12.     {
  13.         if($workingAreaX -gt $item.WorkingArea.X)
  14.         {
  15.             $workingAreaX = $item.WorkingArea.X;
  16.         }
  17.         if($workingAreaY -gt $item.WorkingArea.Y)
  18.         {
  19.             $workingAreaY = $item.WorkingArea.Y;
  20.         }
  21.         $width = $width + $item.Bounds.Width;
  22.         if($item.Bounds.Height -gt $height)
  23.         {
  24.             $height = $item.Bounds.Height;
  25.         }
  26.     }
  27.     $bounds = [Drawing.Rectangle]::FromLTRB($workingAreaX, $workingAreaY, $width, $height);
  28.     $bmp = New-Object Drawing.Bitmap $width, $height;
  29.     $graphics = [Drawing.Graphics]::FromImage($bmp);
  30.     $graphics.CopyFromScreen($bounds.Location, [Drawing.Point]::Empty, $bounds.size);
  31.     $bmp.Save($path);
  32.     $graphics.Dispose();
  33.     $bmp.Dispose();
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement