windowsvbscriptprintscreen

Vbscript Printscreen to MSpaint


Take a screen shot of the active window.

Set Wshshell=CreateObject("Word.Basic")
WshShell.sendkeys"%{prtsc}"
WScript.Sleep 1500

Run Mspaint and paste.

set Wshshell = WScript.CreateObject("WScript.Shell")
Wshshell.Run "mspaint"
WScript.Sleep 500

WshShell.AppActivate "Paint"
WScript.Sleep 500

WshShell.sendkeys "^(v)"
WScript.Sleep 1500

Here, the operation for Taking screenshot of active window works Fine.. Also, it starts with mspaint, but the content is not been pasted in the paint file.


Solution

  • Your ^V parameter to .Sendkeys is wrong, it should be:

    WshShell.sendkeys "^v"
    

    The .Sleep after .AppActivate seems to be critical; I couldn't get it to 'work' until I increased the sleeping time:

    WshShell.AppActivate "Paint"
    WScript.Sleep 5000
    

    Your problem prooves that .Sendkeys is not reliable. Look here, especially the posting of Moby Disk to think about other strategies.