The Perl Script
Let's rewrite the batch file in Listing 1 to demonstrate Perl's
capabilities. First, you need to install Perl for Win32 on your workstation.
Download pw32i310.exe from the ActiveState Tool Web site
(http://www.activestate.com). Place this self-extracting file into the Perl
installation directory (e.g., c:\Perl), and invoke pw32i310.exe to fire up the
installation.
At A in Listing 2, page 184, the script declares three variables: $RegKey,
$RegValue, and @Servers. $RegKey holds the Registry key, $RegValue holds the
Registry value, and @Servers is an array that holds the list of servers.
The script then prompts the user for the key and value, and stores the
user's input in $RegKey and $RegValue. The chop function is a Perl function that
removes the last character from a string. In Listing 1, chop removes the new
line character that results from the user pressing the Enter key after typing
the Registry key and value.
At B in Listing 2, the script opens the file that contains the list of
servers and reads the list into the @Servers array. In this example, the script
expects the servers.txt input file to be an ASCII file with one server name per
line.
Next, the script opens the getregval.txt output file and writes some header
information into it. At C in Listing 2, page 185, the script loops through the
@Servers array, calling the Perl for Win32 Registry functions to connect to the
Registry, retrieve the Registry value, and write the returned value to the
output file. Screen 2, page 183, displays the executing script and the contents
of the output file.
Unlike with the command-line script, you don't have to edit the Perl script
to support additional servers. You simply add them to the servers.txt input
file. In this example, I also enhanced the output file format to make it more
readable.
The Final Script
Listing 3, page 185, presents the Final version of the Registry script.
Before you can run the script, you must install Final for NT Server on your
workstation. A Final source file has an .fc extension, which you must compile to
an .fbi file before you execute it. I compiled this script in the Final IDE, and
then passed it to the Final runtime using the command line
c:\>finalrun getregval.fbi
Final can also generate standalone executable files, but you must buy this
feature as an add-on product option.
The Final script differs from the Perl script primarily in that Final
offers a GUI. Perl for Win32 has no GUI support today, although ActiveState Tool
is working on a GUI. However, you can use an HTML form and a browser as an
alternative interface for the Perl script. Screen 3, page 183, shows the opening
dialog box in the Final script.
Scripting Power
To get an idea of just how powerful some of these scripting languages are,
browse the function libraries that come with the software. I'm sure you'll find
that you can offload to a script some of the day-to-day tasks listed in Figure
1.
To obtain demonstration copies of the scripting tools mentioned in the
sidebar "Scripting Languages for NT," browse the companies' Web sites.
Most sites include example programs to get you up to speed quickly. FastLane's
Final includes an example script for each of the NT functions it supports.
Scripting will continue to evolve. You must look no further than
Microsoft's recent scripting initiatives to see that scripts can play an
important role in enterprise systems management. So try your hand at automating your work with scripts--you might surprise yourself!
You can download the listings in this article from the magazine's Web site, http://www.winntmag.com.
| Figure 1: Example Tasks for Scripting |
Managing access control list (ACL)
Configuring applications
Auditing systems and reporting audits
Managing files and shares
Managing OS patches and upgrades
Managing the registry
Automating repetitive tasks
Configuring servers
Controlling and configuring services
Tracking system availability
Adding, changing, and deleting users
|