|
WSH to Master Your Computer
By Stephen Bucaro
Introduction
Windows users interface with their computer through a graphical environment. Even system
administrators interface with computers through a graphical environment. But it wasn't
always that way. In the early days of computers, system administrators performed their
tasks by typing DOS commands. They also wrote scripts, called "batch files", to perform
system administration tasks. Even regular users had to know something about DOS in order
to use a computer.
Unix and Linux systems also began as command line environments. Even today, Unix and Linux
system administrators have a powerful command line environment that gives them capabilities
well beyond that of a Windows system administrator.
Whereas Unix and Linux started out as multi-tasking operating systems, Windows started
out as a single-task operating system. Although Windows versions 3.1 and earlier appeared
to multi-task, they actually ran DOS programs cooperatively. Microsoft was embarassed
about the fact that Windows was actually DOS in disguise. They could have developed a
multi-tasking DOS, but that was contrary to Microsofts marketing strategy.
Whereas Unix and Linux system administrators could perform powerful tasks through a
multi-tasking command-line environment, Windows system administrators had to use a
convoluted combination of "Microsoft Management Consoles", Control Panel utilities, and
DOS commands to perform tasks.
In the early days, computers had limited speed and capabilities. In order to get programs
to run at a reasonable speed, they had to be "compiled" into machine code. Machine code is
basically the binary ones and zeros that computers understand.
Today's computers are much more powerful. Much of today's programming is written as scripts.
Scripts are text files. When we execute a script, instead of giving the computer Machine code,
we pass the script to an "interpreter" program that creates the machine code on the fly.
The most common use of scripts is on webpages. The script code can be typed directly into
the webpage and then can be executed, or interpreted, any time after the webpage is loaded.
With Windows 2000 and higher, Microsoft included a program called "Windows Scripting Host"
(WSH) that allows scripts to be run on a computer outside of a webpage. In effect, DOS
batch files have returned, except scripts are multi-tasking and have a lot more power.
Scripts are simply text files. To create them all you need is a simple text editor like
Windows Notepad. You have to choose which language you will use to write your script. You can
use any language for which an interpreter has been installed. Interpreters for VBScript and
Java Script (called JScript on Windows) are installed by default.
VBScript is the easiest language to learn, but it's Microsoft proprietary. If VBScript is all
you know, outside of Windows and Internet Explorer you will be programming illiterate. Java
Script has a terse syntax similar to C++ (but without the problem causing pointers). People
from outside the Windows world prefer to use Java Script because it works virtually everywhere.
If you write in VBScript, you save the file with a ".vbs" extension. If you write in Java
Script, you save the file with a ".js" extension. When you double-click on a filename with
a .vbs or .js file extension, the WSH creates a "script object" and passes the script to the
appropriate interpreter based on the file extension.
In the script code, you can use the methods and properties of the script object. The method
you will most commonly use is "CreateObject". For example, you might create a "Network" object.
You could then use methods and properties of the Network object to perform administrative
tasks across the network. Or you might create a "Shell" object to perform administrative
tasks on your local computer.
|