Last active
July 26, 2022 03:39
-
-
Save soruly/889d926fcd4b2b8e8dc113a100b9d988 to your computer and use it in GitHub Desktop.
take screenshot of desktop every 15 seconds
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
Add-Type -AssemblyName System.Drawing | |
$timer = New-Object timers.timer | |
$timer.Interval = 15000 | |
$timer.Enabled = $true | |
$timer.start() | |
Register-ObjectEvent -InputObject $timer -EventName Elapsed -SourceIdentifier PrintScreen -Action { | |
$folderName = Get-Date -Format "yyyy-MM-dd" | |
$fileName = "$(Get-Date -Format "yyyy-MM-dd HH mm ss").jpg" | |
$folderPath = Join-Path "C:\printscreendiary" $folderName | |
$filePath = Join-Path $folderPath $fileName | |
[void](New-Item -ItemType Directory -Force -Path $folderPath) | |
$vc = Get-WmiObject -Class "Win32_VideoController" | |
$width = [convert]::toint32($vc.CurrentHorizontalResolution.tostring()) | |
$height = [convert]::toint32($vc.CurrentVerticalResolution.tostring()) | |
$bmp = New-Object System.Drawing.Bitmap $width, $height | |
$p0 = New-Object System.Drawing.Point 0, 0 | |
$size = New-Object System.Drawing.Size $width, $height | |
$graphics = [System.Drawing.Graphics]::FromImage($bmp) | |
$graphics.CopyFromScreen($p0, $p0, $size) | |
$graphics.Dispose() | |
$encoderParamSet = New-Object System.Drawing.Imaging.EncoderParameters(1) | |
$encoderParamSet.Param[0] = New-Object System.Drawing.Imaging.EncoderParameter([System.Drawing.Imaging.Encoder]::Quality, 90) | |
$jpgCodec = [System.Drawing.Imaging.ImageCodecInfo]::GetImageEncoders() | Where-Object { $_.MimeType -eq 'image/jpeg' } | |
$bmp.Save($filePath , $jpgCodec, $encoderParamSet) | |
$bmp.Dispose() | |
} | |
# Get-EventSubscriber | |
# Unregister-Event -SourceIdentifier PrintScreen |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment