主題のままなのですが、AWSのEC2でテストを消化する機会があり、ファイル収集やキャプチャ取得が面倒だと思ったので、パワーシェルで自動化しました。
キャプチャ取得は、メモ帳とエクスプローラー。
ファイル収集はそんなに難しくないと思うので省略です。
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing
$exeFolder = $MyInvocation.MyCommand.Path
$exeFolder = Split-Path "$exeFolder" -Parent
Function openExprolerAndGetCapture($folderPath) {
# エクスプローラーを開く
Start-Process explorer.exe -ArgumentList $folderPath -WindowStyle Maximized
# ウィンドウが表示されるのを待つ
Start-Sleep -Seconds 5
# エクスプローラーのウィンドウを探す
$folderName = $folderPath.split("\")
#Write-Host $folderName[-1]
$explorerWindow = Get-Process | Where-Object { $_.MainWindowTitle -eq $folderName[-1] }
if ($explorerWindow) {
# 画面キャプチャを取得
$rect = [System.Windows.Forms.Screen]::PrimaryScreen.Bounds
$bitmap = New-Object System.Drawing.Bitmap($rect.Width, $rect.Height)
$graphics = [System.Drawing.Graphics]::FromImage($bitmap)
$zero = New-Object System.Drawing.Point(0, 0)
$graphics.CopyFromScreen($zero, $zero, $bitmap.Size)
# 画像を保存
$saveFileName = $exeFolder + "\" + $folderPath.replace("\", "_").replace(":", "") + ".png"
Write-Host $saveFileName
$savePath = $saveFileName
$bitmap.Save($savePath, [System.Drawing.Imaging.ImageFormat]::Png)
# ウィンドウを閉じる
$explorerWindow.CloseMainWindow()
}
else {
Write-Host "エクスプローラーのウィンドウが見つかりませんでした。"
}
}
Function openNotepadAndGetCapture($filePath) {
# メモ帳を開く
Start-Process C:\Windows\notepad.exe -ArgumentList $filePath -WindowStyle Maximized
# ウィンドウが表示されるのを待つ
Start-Sleep -Seconds 5
# メモ帳のウィンドウを探す
$fileName = $filePath.split("\")
$windowTitle = $fileName[-1] + " - メモ帳"
Write-Host $windowTitle
$explorerWindow = Get-Process | Where-Object { $_.MainWindowTitle -eq $windowTitle }
if ($explorerWindow) {
# 画面キャプチャを取得
$rect = [System.Windows.Forms.Screen]::PrimaryScreen.Bounds
Write-Host $rect.Width ":" $rect.Height
$bitmap = New-Object System.Drawing.Bitmap($rect.Width, $rect.Height)
$graphics = [System.Drawing.Graphics]::FromImage($bitmap)
$zero = New-Object System.Drawing.Point(0, 0)
$graphics.CopyFromScreen($zero, $zero, $bitmap.Size)
# 画像を保存
$saveFileName = $exeFolder + "\" + $filePath.replace("\", "_").replace(":", "").replace(".", "_") + ".png"
Write-Host $saveFileName
$savePath = $saveFileName
$bitmap.Save($savePath, [System.Drawing.Imaging.ImageFormat]::Png)
# ウィンドウを閉じる
$explorerWindow.CloseMainWindow()
}
else {
Write-Host "メモ帳のウィンドウが見つかりませんでした。"
}
}
try {
# memo
openNotepadAndGetCapture -filePath "C:\test\test.txt"
# explorer
openExprolerAndGetCapture -folderPath "C:\test"
}
finally {
}
