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).
|