Windows 2000: Scripting solutions

When it comes to scripting, Windows 2000 offers plenty of choices. Scripting is, in simple terms, the use of an interpreted programming language to automate repetitive tasks, and even build small applications.


The CMD shell in Windows 2000 offers scriptability, similar to the old DOS BATch files, but with more features. As with DOS, a .bat extension tells CMD to treat the script as executable; however, just like NT and OS/2, Windows 2000 also treats files with the .cmd extension as executable scripts.

The native Windows 2000 shell scripting lets you do conditional looping, jumping and branching, and parameter substitution, and call other batch files as well. Global and local environment variables are also supported, plus output redirection with > < << >> and | [pipe] for further processing by other programs. The commands available to you include:call.pause.echo.rem.endlocal.setlocal.for.shift.goto.

% [variable].if.

These commands are well-documented: simply issue the /? switch after each (e.g., for /?) for an exhaustive list of options and sample code; combine this information with the output of the /? for other shell commands (e.g., NET USER) to write the pseudo-code for your script and, ultimately, the script itself.

Unlike UNIX, Windows shell scripts cannot access all areas of the system. There is no way, for example, to script the Disk Defragmenter to run automatically on certain volumes at given intervals, because the Microsoft Management Console (MMC) doesn't provide a command line interface.


A more powerful scripting solution for Windows 2000 is Microsoft's Windows Script, which, among other things, provides a way to script GUI apps - in fact, you could replace the text-only login scripts with VBS (Visual Basic Script) equivalents which provide a nice GUI for users. Windows Script is COM (Component Object Model) aware, giving you access to any system object you like, as long as they are registered with the operating system.

Windows Script requires the Windows Scripting Host (WSH) to be installed, and there have been several security issues with this in the past - some of the most widespread viruses have been VBS ones, using WSH to gain access to important system structures. The latest version (5.6 as of going to press) introduces a new security model that lets users verify scripts before running them. Developers can also sign scripts, to add another layer of authentication and protection against tampering, and administrators can establish policies that allow only certain users to run local and/or remote scripts. Download WSH plus documentation for it from, which also has code examples plus hints and tips for beginners.

WSH also contains Microsoft's JScript scripting engine, a script debugger, and several scripting components, on top of the Windows Script runtime. It allows you to create command-line apps (run them with cscript.exe), GUI ones (run with wscript.exe) and scripts that can be hosted through Active Server Pages on Internet Information Server. It's a comprehensive and complex scripting solution which takes time to master, so investing in some classes and books is a good idea.


If you're looking for a non-Microsoft scripting solution, PERL (, is hard to overlook. Created by Larry Wall, it's a mature and fully-featured interpreted language that has been in use on UNIX for years. There is an abundance of sample code and online tutorials to get you started, not to mention reusable PERL modules that simplify and speed up coding of applications significantly.

Furthermore, with a bit of planning (e.g., don't use WSH objects), your code will run on both Windows and UNIX.

PERL is extremely powerful for text string manipulation. Say you want to replace all instances of "change-me" with "to this" in a number of text files in a directory; if any file is changed, you want to save the original file with a .bak extension.

This PERL one-liner will do it for you:

perl -we "s/change-me/to this /gi" -p -i.bak *.txt

However, writing and maintaining large applications in PERL can be a chore, and it's not the easiest language in the world to learn.

The Win32 version of PERL is provided by ActiveState (www.activestate."com), which also develops Visual Studio plug-ins with a graphical debugger and source code revision control, for the language. ActiveState Perl is very well integrated with Windows and work is in progress to develop a .NET version as well.

Get the 12MB ActivePerl installer from http://downloads.activestate."com/ActivePerl/Windows/5.6/Active"Perl- (Microsoft Installer Package format).

Here are some good sites with sample code, as well as hints and tips for getting started with scripting:

Join the newsletter!


Sign up to gain exclusive access to email subscriptions, event invitations, competitions, giveaways, and much more.

Membership is free, and your security and privacy remain protected. View our privacy policy before signing up.

Error: Please check your email address.
Keep up with the latest tech news, reviews and previews by subscribing to the Good Gear Guide newsletter.

Juha Saarinen

PC World
Show Comments

Most Popular Reviews

Latest Articles


PCW Evaluation Team

Tom Pope

Dynabook Portégé X30L-G

Ultimately this laptop has achieved everything I would hope for in a laptop for work, while fitting that into a form factor and weight that is remarkable.

Tom Sellers


This smart laptop was enjoyable to use and great to work on – creating content was super simple.

Lolita Wang


It really doesn’t get more “gaming laptop” than this.

Jack Jeffries


As the Maserati or BMW of laptops, it would fit perfectly in the hands of a professional needing firepower under the hood, sophistication and class on the surface, and gaming prowess (sports mode if you will) in between.

Taylor Carr


The MSI PS63 is an amazing laptop and I would definitely consider buying one in the future.

Christopher Low

Brother RJ-4230B

This small mobile printer is exactly what I need for invoicing and other jobs such as sending fellow tradesman details or step-by-step instructions that I can easily print off from my phone or the Web.

Featured Content

Product Launch Showcase

Don’t have an account? Sign up here

Don't have an account? Sign up now

Forgot password?