Skip to content

Instantly share code, notes, and snippets.

Last active March 13, 2022 08:38
What would you like to do?
Take a screenshot and open it in image editor
'Ramesh Srinivasan,
'Take a screenshot and open it in image editor
'Requires NirCmd.exe (from to automate Win + PrntScrn
'For Windows 8 and Windows 10.
Set WshShell = CreateObject("WScript.Shell")
Set fso = CreateObject("Scripting.FileSystemObject")
'Sleep for 2 seconds until the user sets the active Window or menu
WScript.Sleep 2000
'Take full screenshot
WshShell.Run "nircmd.exe " & "sendkeypress rwin+printscreen"
'Sleep again for half a second - wait until the PNG file is written
WScript.Sleep 500
Dim fNewest
'Find the latest PNG file in Screenshots folder and Open it in editor.
SShots = WshShell.ExpandEnvironmentStrings("%userprofile%")
SShots = SShots & "\Pictures\Screenshots"
If Not fso.FolderExists(SShots) Then WScript.Quit
For Each f In fso.GetFolder(SShots).Files
If UCase(fso.GetExtensionName(f)) = "PNG" Then
If fNewest = "" Then
Set fNewest = f
ElseIf fNewest.DateLastModified < f.DateLastModified Then
Set fNewest = f
End If
End If
If fNewest <> "" Then WshShell.Run "mspaint.exe " & Chr(34) & fNewest & Chr(34)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment