I want my script to get a screenshot using command prompt/powershell WITHOUT ANY 3RD PARTY TOOLS how can I do that it should look like this "C:\Windows\System32\screenshot.exe" "C:\Users\%username%\Pictures\screenshot.png"
-
1What you describe does not exist. This can only be accomplished by third-party software.– RamhoundCommented Aug 16, 2021 at 14:53
-
4With PowerShell, you have the full power of .NET Framework (or Core) available to you, surely you'll find something.– Daniel BCommented Aug 16, 2021 at 14:55
-
7Windows has native keyboard shortcuts that you can utilize to create a screenshot and place it in the clipboard. All you need to do is send that to the taskbar and save the clipboard to a file. That said, SuperUser is not a script-writing service. If you post your script, we can help you with finding out why its not working, but we won't write a full script for you.– LPChipCommented Aug 16, 2021 at 15:00
-
Just search for PowerShell Screenshot, the first link already tells you everything– SimonSCommented Aug 16, 2021 at 15:07
2 Answers
Guys I've found a way just replace urusername with your username and run this command
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
If you are looking for a script for ease, You should instead use Win + Shift + S
to open Snip and Sketch tool. It is very handy especially if you are a student and take screenshot every now and then.
With that been said, if you still want to take screenshots from command line, you can use the command: explorer ms-screenclip:
. Save this as a batch file, and when you will run this script, this will launch the Snip and Sketch tool in Snipping mode.
-
1Though you can send the keycode for most keys (see stackoverflow.com/questions/9709474/…), apparently sending PrtSc is not as simple: handmade.network/forums/t/… Commented Aug 16, 2021 at 18:20
-
The author wants to take the screenshot not simply launch an application that is capable of taking a screenshot. I have my doubts this answer's the author's question.– RamhoundCommented Aug 16, 2021 at 18:20
-
Thanks for your work guys! I already found a way out though. Commented Aug 16, 2021 at 18:22
-
@TheCodeExpert Pleaswe if you have found a solution, post it as self-answer so others may benefit as well. If the solution came from somewhere, include a link to the original.– TheoCommented Aug 18, 2021 at 12:57