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.

CMD SHELL

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.

WINDOWS SCRIPT

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 http://communities.msn.com/windowsscript, 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.

PERL

If you're looking for a non-Microsoft scripting solution, PERL (www.perl.org, www.perl.com) 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-5.6.1.630-MSWin32-x86.msi (Microsoft Installer Package format).

Here are some good sites with sample code, as well as hints and tips for getting started with scripting:http://cwashington.netreach.net.www.desktopengineer.com.www.adminscripts.net.

Join the newsletter!

Or

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

Father’s Day Gift Guide

Brand Post

Most Popular Reviews

Latest Articles

Resources

PCW Evaluation Team

Luke Hill

MSI GT75 TITAN

I need power and lots of it. As a Front End Web developer anything less just won’t cut it which is why the MSI GT75 is an outstanding laptop for me. It’s a sleek and futuristic looking, high quality, beast that has a touch of sci-fi flare about it.

Emily Tyson

MSI GE63 Raider

If you’re looking to invest in your next work horse laptop for work or home use, you can’t go wrong with the MSI GE63.

Laura Johnston

MSI GS65 Stealth Thin

If you can afford the price tag, it is well worth the money. It out performs any other laptop I have tried for gaming, and the transportable design and incredible display also make it ideal for work.

Andrew Teoh

Brother MFC-L9570CDW Multifunction Printer

Touch screen visibility and operation was great and easy to navigate. Each menu and sub-menu was in an understandable order and category

Louise Coady

Brother MFC-L9570CDW Multifunction Printer

The printer was convenient, produced clear and vibrant images and was very easy to use

Edwina Hargreaves

WD My Cloud Home

I would recommend this device for families and small businesses who want one safe place to store all their important digital content and a way to easily share it with friends, family, business partners, or customers.

Featured Content

Product Launch Showcase

Don’t have an account? Sign up here

Don't have an account? Sign up now

Forgot password?