Qtp wsh scripts examples

5,248 views
4,981 views

Published on

0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
5,248
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
112
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Qtp wsh scripts examples

  1. 1. Visit www.ramupalanki.com Windows Script HostMicrosoft currently offers three hosts for running scripting languagecode. They are:Internet Explorer (IE)- for running client side scripts in the WebInternet Information Server (IIS) -for running Server side scriptsWindows Script Host (WSH)- for running scripts on windowsdesktop and from the Command promtWSH (Windows Script Host)It is Micro Soft Windows Administration Tool to run scriptsWSH is a language-independent scripting host for Windows Scriptcompatible scripting engines. It allows us to run scripts from both theWindows desktop and the command promptWSH Provides hosting environment for running the Scripts. It has 2built-in script enginesi) VBScript (extension .vbs)ii) Jscript (extension .js)If we want run any other scripts like Perl or Python, we have to installthose script engines.WSH provides runtime objects to allow our script code to interact withthe local Computer environment. 1
  2. 2. WSF (Windows Script File) is an XML file format that allows us todefine scripting jobs.Two WSH commands, cscript.exe and wscript.exe, are provided to runscripts with and without a command window.Remote WSHIt is a new technology available in WSH 5.6 Version, It provides afacility to run scripts on remote machines.Windows Script Host Tasksi) Accessing Networksii) Creating Automated Login Script and Logout Scriptiii) Driving Applicationsiv) Manipulating System Registryv) Running Scripts RemotelyEtc… Shell Scripting Examples 1) How to display a message with some wait time? Dim WshShellSet WshShell = CreateObject( "WScript.Shell")WshShell.Popup "Tester", 5, "QTP Training"2) How to run DOS commands using windows shell script? Dim objShellSet objShell = CreateObject ("WSCript.shell" )objShell.run "cmd /K CD C:&Dir"3) How to display Current User Name?Dim objNetwork, objShellSet objNetwork = CreateObject( "WScript.Network")Current_User = objNetwork.usernameSet objShell = CreateObject( "WScript.Shell")objShell.Popup Current_User , 5, " User Name "4) How to send keyboard inputs? set oShell = CreateObject( "WScript.Shell")oShell.SendKeys "Tester" 2
  3. 3. 5) How to get Local Computer Information?Set objComputer = CreateObject("Shell.LocalMachine")Wscript.Echo "Computer name: " & objComputer.MachineNameWscript.Echo "Shutdown allowed: " & objComputer.IsShutdownAllowedWscript.Echo "Friendly UI enabled: " &objComputer.IsFriendlyUIEnabledWscript.Echo "Guest access mode: " &objComputer.IsGuestAccessModeWscript.Echo "Guest account enabled: " & _ objComputer.IsGuestEnabled(0)Wscript.Echo "Multiple users enabled: " & _ objComputer.IsMultipleUsersEnabledWscript.Echo "Offline files enabled: " & _ objComputer.IsOfflineFilesEnabledWscript.Echo "Remote connections enabled: " & _ objComputer.IsRemoteConnectionsEnabledWscript.Echo "Undock enabled: " & objComputer.IsUndockEnabledNote: Run the above script as vbscript file(.vbs), It may notwork in QTP Test Pane.----------------------------------------------------------------We can run VBScript code file directly. But WSH also supports an XMLfile format called .WSF (Windows Script File).WSF file offers an XML structure to define script jobs and group jobsinto a package<package> <job id="VBScriptJob"> <script language="VBScript"> WScript.Echo "Hello Tester! - VBScriptJob" </script> </job> <job id="JScriptJob"> <script language="JScript"> WScript.Echo("Hello Tester! - JScriptJob"); </script> 3
  4. 4. </job></package> 4

×