Windows Script Host (WSH)

  Have you ever executed a VBScript or JavaScript file on your Windows Computer? If you did, then you have used Windows Script Host (WSH) even though you might not have realized it. Even if you haven’t executed any of these scripts on your computer, you should know about WSH. Here, we are going to discuss Windows Script Host and its types i.e. Console Based Script Host (cscript.exe) and Windows Based Script Host (wscript.exe).

Windows Script Host

  Windows Script Host is used to execute scripts written using VBScript  (files with the extension .vbs) and JavaScript (files with the extension .js). As mentioned above, there are two versions of WSH – Windows Based Script Host (wscript.exe) and Console Based Script Host (cscript.exe). The wscript.exe uses a typical Window-based interface for setting script properties. On the contrary, the cscript.exe uses command-line switches for performing this task.

Windows Based Script Host

  The wscript.exe is automatically invoked (by default) whenever you double-click on a script file to execute it. In other words, your scripts execute inside the Windows Based Script Host.

Windows Script Host - Script Running in Windows Based Script Host (wscript.exe)

Windows Script Host – Script Running in Windows Based Script Host (wscript.exe)

Task Manager - Calc.vbs being executed by wscript.exe

Task Manager – Calc.vbs being executed by wscript.exe

  Normally, you don’t need to explicitly execute wscript.exe. It is executed manually only for modifying preferences (settings) which are applicable while executing a script. It can be found at “C:\Windows\System32” or you can also execute it from the command line. The following window appears when you execute this program :

Windows Script Host - Windows Based Version

Windows Script Host – Windows Based Version

  This window lets you modify settings for scripts and make them applicable system-wide i.e. these settings apply to every script you run on the computer. The first setting lets you choose whether you want to stop the scripts after they have been active for the specified no. of seconds. The second setting lets you choose whether the logo is to be displayed when the script is executed at the Command Prompt (CMD).

  You can also apply different settings to individual script files by right-clicking them and going to the Script tab in the Properties Window. When you modify a script’s settings manually, a file with the same name as the script and with the extension .wsh is created. A .wsh file is a text file and has a format similar to that of .ini files. It contains a [ScriptFile] section, which identifies the script file with which the .wsh file is associated, and an [Options] section, which corresponds to the settings selected by you on the Script tab. A .wsh file, when opened using Notepad, looks like this :

A .wsh file

A .wsh file

Console Based Script Host

  The Console Based Script Host (cscript.exe) is located at “C:\Windows\System32”. You can execute it using the command prompt. It performs the same task as the Windows Based Script Host (i.e. modifying preferences) but using command line switches. You can view the various command-line switches for cscript.exe in the image below :

Windows Script Host - Console Based Version

Windows Script Host – Console Based Version

Note : You can execute a script by either double-clicking it or by using the command line (viz. D:\cscript calc.vbs or D:\wscript calc.vbs). Also, there is no difference in the way the script is executed by cscript or wscript. In other words, the output of the script would be the same irrespective of what program you use to execute it. The difference between wscript and cscript lies in their concept. wscript has been designed as a GUI application while cscript is CLI based. 

(Visited 366 times, 1 visits today)

Leave a Reply

Your email address will not be published. Required fields are marked *