How to Access Command prompt from QTP
By Parul Wahi
We can even access Microsoft Windows command prompt also known as MS-DOS from QTP interface.cmd.exe is a 32-bit command prompt used in Windows NT, 2000 and XP and offers disk and file maintenance functions as well as network functions. It can be found under System32 folder.
To launch cmd.exe from QTP write :
SystemUtil.Run “cmd.exe”, “”, “c:\WINDOWS\system32”,”open”
Once DOS window launches, this window can be leant and added to object repository
To write on command prompt window use the following code:
Window( “object class:=ConsoleWindowClass”).Type “Ping crestechsoftware.com”
Window( “object class:=ConsoleWindowClass”).Type micReturn
Using WshShell object
The WshShell object gives your scripts the ability to work with Windows shell .Your scripts can use the WshShell object to perform a number of system administration tasks, including running programs, reading from and writing to the registry, and creating shortcuts.
Following are the list of few methods used with wcript object:
1)The Environment property helps in getting environment variables
2)The Exec method returns a WshScriptExec object, which provides status and error information about a script run with Exec along with access to the StdIn, StdOut, and StdErr channels. The Exec method allows the execution of command line applications only.
3)Pop Up Method Displays text in a pop-up message box.
4)RegRead Method helps in reading from registry
Example
The following example demonstrates the basics of the Exec method.
Dim WshShell, oExec
Set WshShell = CreateObject(”WScript.Shell”)
Set oExec = WshShell.Exec(”calc”)
Do While oExec.Status = 0
WScript.Sleep 100
Loop
WScript.Echo oExec.Status
You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.





Leave a Reply