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!

Error: Please check your email address.
Rocket to Success - Your 10 Tips for Smarter ERP System Selection
Keep up with the latest tech news, reviews and previews by subscribing to the Good Gear Guide newsletter.

Juha Saarinen

PC World
Show Comments

Cool Tech

SanDisk MicroSDXC™ for Nintendo® Switch™

Learn more >

Breitling Superocean Heritage Chronographe 44

Learn more >

Toys for Boys

Family Friendly

Panasonic 4K UHD Blu-Ray Player and Full HD Recorder with Netflix - UBT1GL-K

Learn more >

Stocking Stuffer

Razer DeathAdder Expert Ergonomic Gaming Mouse

Learn more >

Christmas Gift Guide

Click for more ›

Most Popular Reviews

Latest Articles

Resources

PCW Evaluation Team

Ben Ramsden

Sharp PN-40TC1 Huddle Board

Brainstorming, innovation, problem solving, and negotiation have all become much more productive and valuable if people can easily collaborate in real time with minimal friction.

Sarah Ieroianni

Brother QL-820NWB Professional Label Printer

The print quality also does not disappoint, it’s clear, bold, doesn’t smudge and the text is perfectly sized.

Ratchada Dunn

Sharp PN-40TC1 Huddle Board

The Huddle Board’s built in program; Sharp Touch Viewing software allows us to easily manipulate and edit our documents (jpegs and PDFs) all at the same time on the dashboard.

George Khoury

Sharp PN-40TC1 Huddle Board

The biggest perks for me would be that it comes with easy to use and comprehensive programs that make the collaboration process a whole lot more intuitive and organic

David Coyle

Brother PocketJet PJ-773 A4 Portable Thermal Printer

I rate the printer as a 5 out of 5 stars as it has been able to fit seamlessly into my busy and mobile lifestyle.

Kurt Hegetschweiler

Brother PocketJet PJ-773 A4 Portable Thermal Printer

It’s perfect for mobile workers. Just take it out — it’s small enough to sit anywhere — turn it on, load a sheet of paper, and start printing.

Featured Content

Product Launch Showcase

Latest Jobs

Don’t have an account? Sign up here

Don't have an account? Sign up now

Forgot password?