在命令提示符/powershell 上截取屏幕截图

The*_*ert 3 windows screenshot powershell command-line cmd.exe

我希望我的脚本在没有任何第三方工具的情况下使用命令提示符/powershell 获取屏幕截图我该怎么做,它应该看起来像这样"C:\Windows\System32\screenshot.exe" "C:\Users\%username%\Pictures\screenshot.png"

The*_*ert 5

伙计们,我找到了一种方法,只需将 urusername 替换为您的用户名并运行此命令

Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing

$Screen = [System.Windows.Forms.SystemInformation]::VirtualScreen
$Width  = $Screen.Width
$Height = $Screen.Height
$Left   = $Screen.Left
$Top    = $Screen.Top

$bitmap  = New-Object System.Drawing.Bitmap $Width, $Height
$graphic = [System.Drawing.Graphics]::FromImage($bitmap)
$graphic.CopyFromScreen($Left, $Top, 0, 0, $bitmap.Size)

$bitmap.Save("C:\Users\urusername\Desktop\MyFancyScreenshot.bmp")
Write-Output "Screenshot saved to:"
Write-Output C:\Users\urusername\Desktop\MyFancyScreenshot.bmp
Run Code Online (Sandbox Code Playgroud)