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.
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 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.
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-126.96.36.1990-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.