我一直堅持在這最後一天左右,我覺得它的東西很小,我什麼都看不到。PowerShell屏幕捕獲
總結代碼:每60秒運行一次屏幕捕獲的Powershell腳本。在Windows Server 2012上,這很好。而在Windows 7上,只有第一個屏幕截圖被採用,然後全部都是「空白」,只有空白大小的尺寸。任何想法爲什麼發生這種情況
我也嘗試刪除更大的while循環,並執行每5分鐘運行一次的計劃任務,但這又不起作用,我得到的只是一張空白的圖像。有什麼想法嗎?在Windows 7上,我使用本地管理員用戶。
我使用跨越兩個窗口7和Windows Server 2012和.NET的powershell 4 4.5
while($true){
[Reflection.Assembly]::LoadWithPartialName("System.Drawing")
function screenshot([Drawing.Rectangle]$bounds, $path) {
$bmp = New-Object Drawing.Bitmap $bounds.width, $bounds.height
$graphics = [Drawing.Graphics]::FromImage($bmp)
$graphics.CopyFromScreen($bounds.Location, [Drawing.Point]::Empty, $bounds.size)
$bmp.Save($path)
$graphics.Dispose()
$bmp.Dispose()
}
#NUC bounds
$bounds = [Drawing.Rectangle]::FromLTRB(0, -1080, 1920, 1080)
#remote display bounds
#$bounds = [Drawing.Rectangle]::FromLTRB(0, 0, 1280, 800)
$PC_name=$(Get-WmiObject Win32_Computersystem).name
$dateandtime = Get-Date -Format yyyy-MM-dd-hh-mm-ss
$path_pcname= "C:\Scripts\Screenshots\" + $PC_name + "_screenshot_" + "$dateandtime"+ ".png"
screenshot $bounds $path_pcname
$limit = (Get-Date).AddMinutes(-15)
$path_todelete = "C:\Scripts\Screenshots\"
# Delete files older than the $limit.
Get-ChildItem -Path $path_todelete -Recurse -Force | Where-Object { !$_.PSIsContainer -and $_.CreationTime -lt $limit } | Remove-Item -Force
Start-Sleep -Seconds 60
}
編輯: 我意識到,這行: [Reflection.Assembly]: :從GAC讀取的LoadWithPartialName(「System.Drawing」) 未正確啓動。不知道這是否有幫助。
可能你的麻煩來自'System.Drawing'程序集的錯誤工作。嘗試修復你的.NET安裝。 – Vesper