Visit
     www.ramupalanki.com



               Windows Script Host
Microsoft currently offers three hosts for running scripting language
code. They are:

Internet Explorer (IE)- for running client side scripts in the Web

Internet Information Server (IIS) -for running Server side scripts

Windows Script Host (WSH)- for running scripts on windows
desktop and from the Command promt

WSH (Windows Script Host)

It is Micro Soft Windows Administration Tool to run scripts

WSH is a language-independent scripting host for Windows Script
compatible scripting engines. It allows us to run scripts from both the
Windows desktop and the command prompt

WSH Provides hosting environment for running the Scripts. It has 2
built-in script engines

i) VBScript (extension .vbs)
ii) Jscript (extension .js)

If we want run any other scripts like Perl or Python, we have to install
those script engines.

WSH provides runtime objects to allow our script code to interact with
the local Computer environment.



                                                                           1
WSF (Windows Script File) is an XML file format that allows us to
define scripting jobs.

Two WSH commands, cscript.exe and wscript.exe, are provided to run
scripts with and without a command window.

Remote WSH
It is a new technology available in WSH 5.6 Version, It provides a
facility to run scripts on remote machines.

Windows Script Host Tasks
i) Accessing Networks
ii) Creating Automated Login Script and Logout Script
iii) Driving Applications
iv) Manipulating System Registry
v) Running Scripts Remotely
Etc…


        Shell Scripting Examples
 1) How to display a message with some wait time?
 Dim WshShell
Set WshShell = CreateObject( "WScript.Shell")
WshShell.Popup "Tester", 5, "QTP Training"

2) How to run DOS commands using windows shell script?
 Dim objShell
Set objShell = CreateObject ("WSCript.shell" )
objShell.run "cmd /K CD C:&Dir"

3) How to display Current User Name?
Dim objNetwork, objShell
Set objNetwork = CreateObject( "WScript.Network")
Current_User = objNetwork.username
Set 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
5) How to get Local Computer Information?

Set objComputer = CreateObject("Shell.LocalMachine")

Wscript.Echo "Computer name: " & objComputer.MachineName
Wscript.Echo "Shutdown allowed: " & objComputer.IsShutdownAllowed
Wscript.Echo "Friendly UI enabled: " &
objComputer.IsFriendlyUIEnabled
Wscript.Echo "Guest access mode: " &
objComputer.IsGuestAccessMode
Wscript.Echo "Guest account enabled: " & _
  objComputer.IsGuestEnabled(0)
Wscript.Echo "Multiple users enabled: " & _
  objComputer.IsMultipleUsersEnabled
Wscript.Echo "Offline files enabled: " & _
  objComputer.IsOfflineFilesEnabled
Wscript.Echo "Remote connections enabled: " & _
  objComputer.IsRemoteConnectionsEnabled
Wscript.Echo "Undock enabled: " & objComputer.IsUndockEnabled


Note: Run the above script as vbscript file(.vbs), It may not
work in QTP Test Pane.
----------------------------------------------------------------


We can run VBScript code file directly. But WSH also supports an XML
file format called .WSF (Windows Script File).

WSF file offers an XML structure to define script jobs and group jobs
into 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
</job>

</package>




             4

Qtp wsh scripts examples

  • 1.
    Visit www.ramupalanki.com Windows Script Host Microsoft currently offers three hosts for running scripting language code. They are: Internet Explorer (IE)- for running client side scripts in the Web Internet Information Server (IIS) -for running Server side scripts Windows Script Host (WSH)- for running scripts on windows desktop and from the Command promt WSH (Windows Script Host) It is Micro Soft Windows Administration Tool to run scripts WSH is a language-independent scripting host for Windows Script compatible scripting engines. It allows us to run scripts from both the Windows desktop and the command prompt WSH Provides hosting environment for running the Scripts. It has 2 built-in script engines i) VBScript (extension .vbs) ii) Jscript (extension .js) If we want run any other scripts like Perl or Python, we have to install those script engines. WSH provides runtime objects to allow our script code to interact with the local Computer environment. 1
  • 2.
    WSF (Windows ScriptFile) is an XML file format that allows us to define scripting jobs. Two WSH commands, cscript.exe and wscript.exe, are provided to run scripts with and without a command window. Remote WSH It is a new technology available in WSH 5.6 Version, It provides a facility to run scripts on remote machines. Windows Script Host Tasks i) Accessing Networks ii) Creating Automated Login Script and Logout Script iii) Driving Applications iv) Manipulating System Registry v) Running Scripts Remotely Etc… Shell Scripting Examples 1) How to display a message with some wait time? Dim WshShell Set WshShell = CreateObject( "WScript.Shell") WshShell.Popup "Tester", 5, "QTP Training" 2) How to run DOS commands using windows shell script? Dim objShell Set objShell = CreateObject ("WSCript.shell" ) objShell.run "cmd /K CD C:&Dir" 3) How to display Current User Name? Dim objNetwork, objShell Set objNetwork = CreateObject( "WScript.Network") Current_User = objNetwork.username Set 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.
    5) How toget Local Computer Information? Set objComputer = CreateObject("Shell.LocalMachine") Wscript.Echo "Computer name: " & objComputer.MachineName Wscript.Echo "Shutdown allowed: " & objComputer.IsShutdownAllowed Wscript.Echo "Friendly UI enabled: " & objComputer.IsFriendlyUIEnabled Wscript.Echo "Guest access mode: " & objComputer.IsGuestAccessMode Wscript.Echo "Guest account enabled: " & _ objComputer.IsGuestEnabled(0) Wscript.Echo "Multiple users enabled: " & _ objComputer.IsMultipleUsersEnabled Wscript.Echo "Offline files enabled: " & _ objComputer.IsOfflineFilesEnabled Wscript.Echo "Remote connections enabled: " & _ objComputer.IsRemoteConnectionsEnabled Wscript.Echo "Undock enabled: " & objComputer.IsUndockEnabled Note: Run the above script as vbscript file(.vbs), It may not work in QTP Test Pane. ---------------------------------------------------------------- We can run VBScript code file directly. But WSH also supports an XML file format called .WSF (Windows Script File). WSF file offers an XML structure to define script jobs and group jobs into 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.