Problem with WScript object

1,706 views
Skip to first unread message

Praveen Kumar

unread,
Jul 31, 2008, 10:26:13 AM7/31/08
to QTP - HP Quick Test Professional - Automated Software Testing
hi all,
For the following line, QTP is throwing an error "WScript
object required"

set WshShell = WScript.CreateObject("WScript.Shell")

While the code is working fine, when i separately run a vbs file (by
jus double-clicking it)...

Why the same line in vbs file is running fine whereas when executed
from QTP is not running??

Anyone please explain.

Roman Zilber

unread,
Jul 31, 2008, 10:51:01 AM7/31/08
to Mercu...@googlegroups.com

You can't use WScipt in QTP this way, change

Set WshShell = WScript.CreateObject("WScript.Shell") --> Set WshShell = CreateObject("WScript.Shell")

Anshoo Arora

unread,
Jul 31, 2008, 11:02:28 AM7/31/08
to QTP - HP Quick Test Professional - Automated Software Testing
The reason why WSCript. is not working in QTP because it is the root
object of WSH and it is ALWAYS available from the script file. I'm
quite sure there is some information regarding this in QTP's help
file. Simply put, you "cannot" create the WScript object in QTP.

The solution is in the previous post. CreateObject will work without
initializing the WScript object.

Praveen Kumar S

unread,
Jul 31, 2008, 2:48:18 PM7/31/08
to Mercu...@googlegroups.com
i got it... but i somehow need to use WScript to trigger a mail. check my code snippet.


Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "Outlook"
WScript.Sleep 2500
WshShell.SendKeys "^{n}"            ' Ctrl + N to trigger 'new mail'
WScript.Sleep 2000
WshShell.SendKeys "pra...@gmail.com"
WshShell.SendKeys "{TAB}"
WshShell.SendKeys "{TAB}"
WshShell.SendKeys "{TAB}"
WshShell.SendKeys "Task Status"
WshShell.SendKeys "{TAB}"
WScript.Sleep 1000
WshShell.SendKeys "Message body "
WshShell.SendKeys "%{s}" ' Alt + S   to trigger 'send mail'

PS: Due to some reasons, i could not use the object "CDO.Message" or "Outlook.Application" for sending emails.

So let me know how to execute the second line.



Roman Zilber

unread,
Jul 31, 2008, 2:58:23 PM7/31/08
to Mercu...@googlegroups.com
Set WshShell = CreateObject("WScript.Shell")
WshShell.Run "Outlook"
Wait(3)

WshShell.SendKeys "^{n}"            ' Ctrl + N to trigger 'new mail'
Wait(2)

WshShell.SendKeys "pra...@gmail.com"
WshShell.SendKeys "{TAB}"
WshShell.SendKeys "{TAB}"
WshShell.SendKeys "{TAB}"
WshShell.SendKeys "Task Status"
WshShell.SendKeys "{TAB}"
Wait(1)

WshShell.SendKeys "Message body "
WshShell.SendKeys "%{s}" ' Alt + S   to trigger 'send mail'

Praveen Kumar S

unread,
Jul 31, 2008, 3:27:25 PM7/31/08
to Mercu...@googlegroups.com
That worked fine.... thanks Zilber...
Reply all
Reply to author
Forward
0 new messages