Windows Scripting Host

Another handy Active Scripting tool is the Windows Scripting Host (WSH). WSH exposes an object model that makes it particularly suitable for tasks that are normally attempted with Windows batch files. WSH is often used for general Windows administration and can run the logon scripts as each user logs on to the network.

The Windows Scripting Host is included with Windows 98 and 2000, or can be obtained from http://msdn.microsoft.com/scripting for Windows 95 and NT. It’s packaged as two executables: cscript.exe , a command-line tool, suitable for running from the Windows command prompt; and wscript.exe , a GUI application generally run from Windows Explorer.

WSH uses simple text files to hold the script code; Python files run under the Windows Scripting Host using the extension .pys. There are no tags or any other special characters needed, so WSH files that use Python are syntactically identical to a Python source file. The only difference is that if the code were executed directly by Python, the object model exposed by WSH is not available.

Version 5 of the Windows Scripting Host supports the objects described in Table 21.2.

Table 21.2. Windows Scripting Host Top-Level Objects

Object

Description

WScript

The top-level object containing information about the script being executed or the version of WSH, and methods to take specific actions, such as display a message, or create a COM object

WshArguments

An object exposed via Wscript.Arguments that provides ...

Get Python Programming On Win32 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.