Skip to content

Instantly share code, notes, and snippets.

@asears
Created November 10, 2020 01:21
Show Gist options
  • Select an option

  • Save asears/20b8e9c3dfe6d82969711ef19411fecd to your computer and use it in GitHub Desktop.

Select an option

Save asears/20b8e9c3dfe6d82969711ef19411fecd to your computer and use it in GitHub Desktop.
Because that's why...
# https://superuser.com/questions/1072516/open-the-start-menu-using-powershell
(New-Object -ComObject "wscript.shell").SendKeys("^{ESC}")
Start-Sleep 2
(New-Object -ComObject "wscript.shell").SendKeys("This Pc")
Start-Sleep 2
(New-Object -ComObject "wscript.shell").SendKeys("+{F10}")
(New-Object -ComObject "wscript.shell").SendKeys("s")
Start-Sleep 2
(New-Object -ComObject "wscript.shell").SendKeys("p")
(New-Object -ComObject "wscript.shell").SendKeys("{ENTER}")
# https://stackoverflow.com/questions/2969321/how-can-i-do-a-screen-capture-in-windows-powershell
Add-Type -AssemblyName System.Windows.Forms,System.Drawing
$screens = [Windows.Forms.Screen]::AllScreens
$top = ($screens.Bounds.Top | Measure-Object -Minimum).Minimum
$left = ($screens.Bounds.Left | Measure-Object -Minimum).Minimum
$width = ($screens.Bounds.Right | Measure-Object -Maximum).Maximum
$height = ($screens.Bounds.Bottom | Measure-Object -Maximum).Maximum
$bounds = [Drawing.Rectangle]::FromLTRB($left, $top, $width, $height)
$bmp = New-Object System.Drawing.Bitmap ([int]$bounds.width), ([int]$bounds.height)
$graphics = [Drawing.Graphics]::FromImage($bmp)
$graphics.CopyFromScreen($bounds.Location, [Drawing.Point]::Empty, $bounds.size)
$bmp.Save("$env:USERPROFILE\test.png")
$graphics.Dispose()
$bmp.Dispose()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment