Spread the love
  • 23
  • 24
  • 16
  • 23

Windows Script Host (WSH)?
Windows Script Host (WSH)?

What is Windows Script Host (WSH)?

By technology,it is a program that runs within windows environment and acts as a container to run VbScript files.It is a Windows administration tool. WSH creates an environment for hosting scripts.That is, when a script arrives at your computer, WSH plays the part of the host . It makes objects and services available for the script and provides a set of guidelines within which the script is executed. Among other things, Windows Script Host manages security and invokes the appropriate script engine. Windows Script Host is built into Microsoft Windows 98, 2000, and Millennium Editions and higher versions.A Windows script is a text file. We can create a script with any text editor as long as we save our script with a WSH-compatible script extension (.js, vbs, or .wsf).WSH also supports to write scripts in JScript,Perl,Phython,REXX,other ActiveX scripting laguage including VBScript.

List of Supporting technologies


.batMSDOS batch file
.aspASP pages
.htmHTML Webpages
.htmlHTML Webpages
.jsjscript file
.vbsVbScript file
.wshWindows Script host files
.wsfWindows Script host files

Common Editor for WSH Scripts

The most commonly available text editor is already installed on our computer ? Notepad. We can also use your favorite HTML editor, VbsEdit, Microsoft Visual C++, or Visual InterDev.

Below are the popular VBScript /VBS editors

There are hundreds of Text editor available for WSH scripts to write VbScript,VBS code. Below are my choices:

From where to download WSH

WSH can be downloaded from here.

How to Write Code for WSH or VBScript or VBS

Creating a script with Notepad

  1. Start Notepad.
  2. Write your script. For example purposes, type Msgbox “Hello VB Script”
  3. Save this text file with a .vbs extension (instead of the default .txt extension). For example, Hello.vbs
  4. Navigate to the file you just saved, and double-click it.
  5. Windows Script Host invokes the VB Script engine and runs your script. In the example, a message box is displayed with the message “Hello VB Script”
  6. Hosting Environments and Script Engines

Scripts are often embedded in Web pages, either in an HTML page (on the client side) or in an ASP page (on the server side).In the case of a script embedded in an HTML page, the engine component that interprets and runs the script code is loaded by the Web browser, such as Internet Explorer.In the case of a script embedded in an ASP page, the engine that interprets and runs the script code is built into Internet Information Services (IIS).Windows Script Host executes scripts that exist outside an HTML or ASP page and that stand on their own as text files.

How to Run WSH Scripts

We can execute WSH Scripts in the following manners:
  1. Using commandline. It uses Cscript.exe . It is used in MSDOS console window.
  2. Within Windows like double click on the script file.It uses WScript.exe. It is used in Windows GUI.

Cscript commands


we can pass arguments to the Cscript as well:

Cscript<filepath><filename>.<extension> [Options...][Argument1],....[ArgumentN]

The switches available to run a Cscripts are as follows:

//BBatch mode on Suppress the errors
//DEnable debugging
//E:engineExecutes scripts by using engine
//H:CscriptChanges the host to Csript
//H:WscriptChanges the host to Wscript
//IActivates interactive mode
//Job:XXXExecutes a WSF job
//LogoActivates and display a Logo
//NoLogoDeactivate logo display
//SSaves the command line options for active user
//T:nnSets time out in Seconds. A script can run ‘nn’ seconds. Post this time out the script just aborts
//XRun the script in Debugger mode
//UActivates Unicode for redirecting IO from console

Available Script Engines or Alternative of WSH

Generally, we write scripts in either Microsoft JScript or VBScript, the two script engines that ship with Microsoft Windows 98, 2000 and Millennium Editions.We can use other script engines, such as Perl, REXX, and Python, with Windows Script Host.A stand-alone script written in JScript has the .js extension; a stand-alone script written in VBScript has the .vbs extension. These extensions are registered with Windows. When we run one of these types of files, Windows starts Windows Script Host, which invokes the associated script engine to interpret and run the file.

WSH Object Model

WshShellProvides access to native Windows Shell.

WshShell Object has three properties:

  • CurrentDirectory
  • Environment
  • SpecialFolders

WshShell Object provides eleven methods:

  • AppActivate()
  • CreateShortcut()
  • ExpandEnvironmentStrings()
  • LogEvent()
  • Popup()
  • Run()
  • SendKeys()
  • Exec()
  • RegDelete()
  • RegRead()
  • RegWrite()
WshShortcutProvides coders to create shortcut.

WshShortcut Object provides nine properties:

  • Arguments
  • Description
  • FullName
  • Hotkey
  • IconLocation
  • RelativePath
  • TargetPath
  • WindowStyle
  • WorkingDirectory

WshShortcut provides one method:

  • Save()
WshSpecialFoldersProvides access to the special folders.

The special folders are:

  • Templates
  • Startup
  • StartMenu
  • SendTo
  • Recent
  • Programs
  • PrintHood
  • NetHood
  • MyDocuments
  • Fonts
  • Favorites
  • Desktop
  • AllUsersStartup
  • AllUsersStartMenu
  • AllUsersPrograms
  • AllUsersDesktop

WshSpecialFolders object provides two properties:

  • Item
  • Length

WshSpecialFolders object provides one method:

  • Count()
WshUnnamedProvides access to unnamed commands in Command line arguments. WshUnnamed object being a read only collection, generally returned by Unnamed property of the WshArguments object.It uses a zero based index to get the arguments.

The ways to access command line arguments:

  • Access arguments with no names.
  • Access arguments with only names.
  • Access all the arguments.

WshUnnamed object provides two properties:

  • Item
  • Length

WshUnnamed object provides one method:

  • Count()
WshUrlShortcutProvides coders to create shortcut from Internet.

WshUrlShortcut object provides two properties:

  • TargetPath
  • FullName

WshUrlShortcut object provides one method:

  • Save()
WshScriptExecProvides error and status of the script.

WshScriptExec has six properties:

  • ExitCode
  • ProcessID
  • Status
  • StdOut
  • StdIn
  • StdErr

WshScriptExec does not have any method.

WshRemoteErrorProvides error and status of the scrip when it terminates in remote.

WshRemoteError provides six properties:

  • Description
  • Line
  • Character
  • SourceText
  • Source
  • Number

WshRemoteError does not have any method.

WshRemoteProvides access to remote scripts.

WshRemote has two properties:

  • Status
  • Error

WshRemote has two methods:

  • Execute()
  • Terminate()
WshNetworkProvides access to shared resources in network.

WshNetwork has three properties:

  • ComputerName
  • UserDomain
  • UserName

UserName has eight methods:

  • AddWindowsPrinterConnection()
  • AddPrinterConnection()
  • EnumNetworkDrives()
  • EnumPrinterConnection()
  • MapNetworkDrive()
  • RemoveNetworkDrive()
  • RemovePrinterConnection()
  • SetDefaultPrinter()
WshNamedProvides access to named commands in Command line arguments.

Spread the love
  • 23
  • 24
  • 16
  • 23


Please enter your comment!
Please enter your name here