我正在运行一个截取屏幕截图并保存到文件的脚本。我是新手,在集成鼠标事件时遇到困难,所以现在我将手动完成部分任务。
$File = "C:\Users\mydirectory\image1.bmp"
Add-Type -AssemblyName System.Windows.Forms
Add-type -AssemblyName System.Drawing
这是我试图添加一些内容以达到以下效果的地方:
Do while $File -ne "C:\Users\mydirectory\image500.bmp"
我知道这不是正确的语法,但我很难让它发挥作用。
# Gather Screen resolution information
$Screen = [System.Windows.Forms.SystemInformation]::VirtualScreen
$Width = 2560
$Height = 1440
$Left = $Screen.Left
$Top = $Screen.Top
# Create bitmap using the top-left and bottom-right bounds
$bitmap = New-Object System.Drawing.Bitmap $Width, $Height
# Create Graphics object
$graphic = [System.Drawing.Graphics]::FromImage($bitmap)
# Capture screen
$graphic.CopyFromScreen($Left, $Top, 0, 0, $bitmap.Size)
# Save to file
$bitmap.Save($File)
Write-Output "Screenshot saved to:"
Write-Output $File
这就是我迷路的地方。我在这里想要完成的是隔离文件名末尾的数字并添加 1,循环直到达到我上面设置的数字。
Start-Sleep -s 4
我的循环中有一个睡眠语句,因为我将手动单击鼠标。
你可以这样做:
$i = 0
do {
$i++
$File = "C:\Users\mydirectory\image$i.bmp"
} until (-not (Test-Path -LiteralPath $File) -or $i -ge 500)
这会增加数字 ($i
) 直到找到不存在的文件名或$i
达到500。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)