Skip to content

Instantly share code, notes, and snippets.

@winhelponline
Last active March 13, 2022 08:38
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save winhelponline/ea605151dd2b1e8a7efdc8e64e2f9a8b to your computer and use it in GitHub Desktop.
Save winhelponline/ea605151dd2b1e8a7efdc8e64e2f9a8b to your computer and use it in GitHub Desktop.
Take a screenshot and open it in image editor
'Ramesh Srinivasan, Winhelponline.com
'Take a screenshot and open it in image editor
'Requires NirCmd.exe (from www.nirsoft.net) 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
Next
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