WSH – Home

Introduction to WSH (Windows Scripting Host)

The key word in understanding WSH is Host.  WSH (Windows Scripting Host) provides the environment to run scripts like VBScript or JScript.  This is a big improvement over running .bat files in the CMD/DOS ‘host’.  Another analogy is the way Internet Explorer acts as a ‘host’ for displaying Dynamic HTML.

The more you learn about WSH, the more you realize how versatile this host is.  For starters, it supports not only VBScript, but also JScript, Perl, Rexx and Python.  WSH leverages objects and methods from WMI (Windows Management Instrumentation) and ADSI (Active Directory Service Interface).

The secret of WSH, like any good host, is the ability to look after its guests; in this case to service WMI and ADSI requests.  In practical terms, it means that you creating scripts which interact with the Windows Server operating system.

VBScript (or other scripting language)

If WSH is the host or container, then think of VBScript as the glue.  What actually happens is VBScript attaches to ADSI and then pastes the user object into the script.

WSH in action

  • Logon Scripts – Mapping network drives (Native WSH)
  • Creating Active Directory objects – Bulk import of users (Using ADSI)
  • Collecting operating system data – Memory, uptime or free disk space (WMI)
  • Starting or Stopping services – Telnet, System Attendant or Netlogon (WMI)


CScript.exe and WScript.exe

These are the actual executables that perform all the WSH tasks.  Mostly I use the command line CScript.  The latest version of CScript is 5.6, this is built-in to Windows Server 2003.  Windows 2003 ships with version 2.0 but this is upgraded to the 5.6 version when you install Service Pack 3 or later. 

You can check out either CScript or WScript by simply running either at the CMD prompt.  Also investigate file type association to make the connection between .vbs extensions and CScript.exe (Windows Scripting Host).

Topic – Simple WSH Script

The purpose of my sample script is to check the version numbers of WSH, VBScript, WMI, and ADSI.

This is what the output of your script will look like.  Note the subtle differences in the names of the 4 executables: WSH, VBScript, WMI and ADSI.  Check out the part of the script where the major and minor version numbers are joined (concatenated) to echo the final result.


Guy Recommends: Permissions Analyzer – Free Active Directory ToolFree Permissions Analyzer for Active Directory

I like thePermissions Monitor because it enables me to see quickly WHO has permissions to do WHAT.  When you launch this tool it analyzes a users effective NTFS permissions for a specific file or folder, takes into account network share access, then displays the results in a nifty desktop dashboard!

Think of all the frustration that this free utility saves when you are troubleshooting authorization problems for users access to a resource.  Give this permissions monitor a try – it’s free!

Download Permissions Analyser – Free Active Directory Tool

Simple Script

Here is a sample script to check your version of WSH and WMI.


‘Script to display WSH, VBScript, WMI, and ADSI versions
‘Script created by Guy Thomas

On Error Resume Next

WScript.Echo "WSH Version: " & WScript.Version

Wscript.Echo "VBScript Version: " & ScriptEngineMajorVersion _
& "." & ScriptEngineMinorVersion

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer _
& "\root\cimv2")
Set colWMISettings = objWMIService.ExecQuery _
("Select * from Win32_WMISetting")
For Each objWMISetting in colWMISettings
Wscript.Echo "WMI Version: " & objWMISetting.BuildVersion

Set objShell = CreateObject("WScript.Shell")
strAdsiVersion = _
objShell.RegRead("HKLM\SOFTWARE\Microsoft\Active Setup\Installed Components\{E92B03AB-B707-11d2-9CBD-0000F87A369E}\Version")
If strAdsiVersion = vbEmpty Then
strAdsiVersion = objShell.RegRead("HKLM\SOFTWARE\Microsoft\ADs\Providers\LDAP\")
If strAdsiVersion = vbEmpty Then
strAdsiVersion = "ADSI is not installed."
strAdsiVersion = "2.0"
End If
End If
WScript.Echo "ADSI Version: " & strAdsiVersion

Copy the above script into Notepad

Save with a .vbs extension, e.g. guydemo.vbs.

Double click to execute.

Try another script?

Create Users

See Also