Facebook

Course Name Start Date Time Duration Registration Link
No Training Programs Scheduled ClickHere to Contact
Please mail To sudhakar@qtpsudhakar.com to Register for any training

Wednesday, June 17, 2009

How to take screenshot using VBScript?

'**************************************************
'Taking Screenshot using word object
Set oWordBasic = CreateObject("Word.Basic")
oWordBasic.SendKeys "{prtsc}" 
oWordBasic.AppClose "Microsoft Word"
Set oWordBasic = Nothing
WScript.Sleep 2000
 
'Opening Paint Application
set WshShell = CreateObject("WScript.Shell")
WshShell.Run "mspaint"
WScript.Sleep 2000
 
'Some times Paint Application is not activating properly
'To activate MS Paint properly i have minimized and restored the opened windows
set shl=createobject("shell.application")  
shl.MinimizeAll  
WScript.Sleep 1000
shl.UndoMinimizeAll
Set shl=Nothing
WScript.Sleep 1000
 
'Activating Paint Application
WshShell.AppActivate "untitled - Paint"
WScript.Sleep 1000
 
'Paste the captured Screenshot
WshShell.SendKeys "^v"
WScript.Sleep 500
 
'Save Screenshot
WshShell.SendKeys "^s"
WScript.Sleep 500
WshShell.SendKeys "c:\test.bmp"
WScript.Sleep 500
WshShell.SendKeys "{ENTER}"
 
'Release Objects
Set WshShell=Nothing
WScript.Quit
'************************************************** 

I got some issues when i have activated using WshShell.AppActivate "untitled - Paint".
Then I tried minimizing and Restoring the opened windows using shell.Application and its working fine.
If 
WshShell.AppActivate "untitled - Paint" statement is working good for you then remove the maximize, minimize script block to save time.

6 comments :

  1. Nice post. Thanks. All your posts are very useful for us.

    ReplyDelete
  2. This is very helpful...Thx Sudhakar for sharing the info..

    The only thing of puzzle is why we require to use Word Object to take the screenshot, I observed that if we do not use word object then screenshot cannot be taken or its blank..
    Thx

    ReplyDelete
  3. This is very useful... Thanks ..

    ReplyDelete
  4. Superb Annaya Hatsoff to your site

    Pavankumar chennam

    ReplyDelete
  5. Hi Sudhakar,

    Any idea how to capture screen shot from a machine where MS Word is not installed, I need to access a URL from a server and then capture it's screen shot for every 15 min, is there a way for this

    ReplyDelete