Edinburgh Castle
Win32 Perl Scripting: The Administrator's Handbook
AuthorDave Roth
PublisherNew Riders
ISBN1578702151
DateOct 31, 2000
Pages371
Price$35 retail
Price$31.50 from publisher
Price£21 - £35 from Amazon.co.uk
ReviewerAnthony Randell
Cover image for Win32 Perl Scripting

I have one big gripe with this book - I wasn't aware of it when I was mucking around with Windows NT and it would have saved me a lot of time. I can't really blame that on Dave Roth of course...

Overall the book is excellent, it would have saved me many times the cover price had I known of it. If you're doing any administration work on Windows then I recommend you buy it.

Who should read:

Windows Administrators. Perl makes it simple to automate tedious tasks that would otherwise have to be done manually (as in, repetitively, boringly) using the GUI.

Perl conversant Unix/Linux Admin. I.e. anyone who also has to look after some Windows machines and wants to know how to run tasks in the background, or how to do simple user setup, or how permissions work... Dave Roth answers some basic questions that can take a lot of digging to uncover.

Note that:

The book presupposes a basic level of Perl knowledge and does not go into Perl basics at all. This is appropriate as a chapter on Perl would be a loss of focus. It may put off some Windows administrators and that would be a shame.

The book does not go into detail on Windows 32 internals or architecture either, it however briefly discusses the relevant concepts, enough so that the issues are understood. This is appropriate as many of the books audience will not be familiar with how Windows behaves.

It's not a replacement for a Windows administration reference however.

Dave Roth has contributed many Perl modules (Win32::ODBC, Win32::AdminMisc, Win32Daemon, and Win32::Perms) and is also the author of "Win32 Perl Programming: The Standard Extensions". He has a great deal of experience and it shows.

Comments:

The code does not use strict or warnings. Almost all scripts will need configuring so there is potential for mistakes. Easily solved but probably worth a mention at the start. You can download code, to save your fingers from www.roth.net.

The book is not overly verbose and there is a high script to text ratio. It is however, well written and easy to read. The book is not intended as a reference book to the various Perl interfaces to the Windows API (if interested, check out Dave Roth's companion volume "Win32 Perl Programming: The Standard Extensions") but it will give you valuable tools, ideas, and strategies on how to manage your network better.

Reasons to buy this book:

The Windows API is not intuitive and the documentation is cryptic - interfacing to the various modules takes trial and error, blood, sweat and curses. Administrators generally do not have that luxury, and this book will save a lot of time - and some profanities.

The book contains some excellent examples that would be useful immediately as is, and provides plenty of ideas for further development.

Windows has no native character line interface worth mentioning (batch files do not expose the API and are very limited). You can buy a wide variety of system administration tools, but these are non-standard (every site uses something subtly different) and they all cost money. Most of the tools use the Win32 API, which means that using the Perl interfaces it is possible to duplicate these tools quickly and flexibly.

Most Windows system tools only operate on the single machine, so to do something on a different server you need to physically log on to the console, either by walking there or using remote control software - this is a pain when your server is a long way away and your company won't fork out another remote control license (or the remote control software doesn't play nicely with the other applications). Permissions are a complete swine to administer under Windows NT. This is done through the GUI (I know of no Windows CLI to do this), and it's dead slow. Dave Roth has supplied some scripts to report on, take ownership and backup/restore permissions. I'd put these as worth the price of admission alone.

There are some scripts for dumping machine configuration to text files for easy backup and recovery. Many of these do things like restoring the shared drives that are usually ignored but can take effort to recover. I especially liked the script for recovering file permissions - it's quite easy to blow away the permissions on a sub-directory inadvertently and I've done this several times only to face a laborious recovery task.

Not all the book is devoted to working around the lack of CLI tools in Windows, there's a very interesting section on some scripts working with multiple data streams in a single file. Aka NTFS Streams, these allow the same file to have multiple data streams -- think of it as similar to an Excel document with multiple sheets - one file and many separate pages of data). This is something that I'd envisage as very useful for managing error logs (e.g. different streams for different event classes) but it's apparently largely unknown (I was completely ignorant). The standard Windows commands and tools don't work well with data streams but you can expose them with some of the Perl scripts in this book.

Services (aka running tasks in the background in Windows) are a huge potential "gotcha" in Windows, depending on how they are setup they can or cannot access the network. This caused me much pain as some proprietary code demanded a network, which I couldn't see when my scripts were running as a service. I eventually got round this with some crufty code listening on a port. Dave discusses the pitfalls with services and several good strategies for dealing with them, as well as more elegant Daemon strategies for Windows and some robust code samples.

Chapters (followed by a brief and INCOMPLETE description of SOME of the highlights):

  1. Perl and the admin - Short advocacy section, some win32 setup tips and tricks.
  2. Account maintenance - Creating/ maintaining/ disabling, assigning rights without touching the GUI.
  3. Tools - File system, file and directory permissions, TCP/IP configuration, registry delving.
  4. Crisis management - Back up and recovering files, permissions, tracking security breaches.
  5. Monitoring and reporting - Monitoring and searching windows events, automating paging and email alerts.
  6. Logon Scripts - Including an example unified login script.
  7. Processes - "ps -ef" for Windows. Including how to query processes on networked machines and kill them and some tips on getting 'backtick'ed commands to work correctly.
  8. Win32 Services - Running things in the background made easy.
  9. ADSI and WMI - Interfaces to a new set of APIs that provide enhanced reporting and control over Windows.
Links:

http://www.roth.net/books/handbook/ - Dave Roth's site including some errata and various mailing lists, scripts (plus the code for the book) and other useful stuff.

http://www.newriders.com/ - Publishers. Sample chapter

faded separator

Page maintained via github.com/edinburgh-pm/edinburgh.pm