Power Tools Gear
July 5, 2000
By Karen Kenworthy
IN THIS ISSUE
I hope none of my British friends will take it personally, but I've been celebrating American Independence day. It was just 224 years ago that my forefathers declared their independence from King George III. And we've been congratulating ourselves ever since.
Eating hotdogs must be a later addition to the celebration. Or maybe not. But fireworks definitely have been a part of the tradition from the beginning. And I've had my fill of both, at least until next year. I hope the last few days have been good for you too, no matter where you stand on the war. :)
Speaking of conflicts, I recently received an ominous message from Dr. Terry Rowe. In it he wrote "Karen, this may sound impertinent, but from a user's perspective, I wonder why we can't just right-click on a directory and have an entry like "print directory" appear linking us to your utility. This IS meant to be constructive!" Just in case I still might misconstrue his intent, he included a cute smiley face above his signature.
Now I'm not sure what I might have said to make Dr. Rowe so afraid of my reaction. I'm usually pretty easy-going. Why, I can't remember the last time I killed a reader. Well, not for making a constructive suggestion, anyway.
But I want to put everyone at ease. I wasn't the least bit annoyed this suggestion. In fact, Dr. Rowe has a *great* idea. Why shouldn't we be able to print a directory with the click of a mouse? It's something Windows ought to let us do. So why can't we?
It turns out we can. All that's required is a little Registry magic. Or some help from a friend. First, the hard way, by changing the Registry ourselves.
We've all seen those cute little right-click "context" menus. They appear when you place your mouse pointer over an icon, and click once with your right mouse button. Depending on the icon you've selected, you might see menu choices like Open, Explore, Copy, Create Shortcut, or Properties. If the icon represents a file, you might even see a choice reading "Print." But you'll never see that choice on the context menu that appears above a folder or a drive icon. Never, that is, unless you read on ...
The choices you see in those context menus are controlled by entries in the HKEY_CLASSES_ROOT branch of the Windows Registry tree. This large, but obscure, section is where Windows records who can do what to whom. Here you'll find, for example, links to portions of programs, called objects, that other programs may access. You'll also discover which programs open, by default, each type of file.
You probably remember from some of our other talks how the Registry is organized. It's a lot like a hard disk, where bits of information are stored in files, and files reside on drives, within directories and subdirectories. At this moment, for example, this note to you is being stored in a file named PT- 000705.doc. This file resides in the \My Documents\Word\Newsletters folder on my C: drive. So, its full "address" is:
Instead of drives, the Registry stores information within HKEYS (Handles to Keys). Each HKEY contains several subkeys (similar to directories and subdirectories). At the end of each chain of subkeys, you'll find one or more data locations (analogous to files) each holding a single chunk of data. Most data locations have names, though each branch of the Registry has a "default" location, a place with no name where one bit of data can be stored.
Deep within your Windows Registry, for example, you should find this small branch: HKEY_CLASSES_ROOT\Folder\shell\Explore\. The existence of this branch tells Windows Explorer to display a choice reading "Explore" in the context menus that appear above folders. Nearby you'll also find a branch of the Registry that begins with HKEY_CLASSES_ROOT\Folder\shell\Open. As you've probably guessed, this branch causes Explorer to add "Open" to each folder's context menu.
Do It Yourself
Adding choices to the Folder context menu is as easy as adding new subkeys to the Windows Registry. To see how easy that is, let's start by selecting Run from Windows' Start menu, and running a program named RegEdit.
Once RegEdit starts, it displays names of all HKEYS found in your Registry. Clicking on the plus sign ("+") beside one of those names produces a list of the subkeys immediately below that HKEY. Click on the plus sign beside a subkey's name, and you'll see any subkeys it might hold. In the right pane of RegEdit's window you'll see all data locations and values stored within a selected subkey.
You can literally spend all day exploring your Registry this way, since the Registry contains thousands of subkeys, and even more data locations and values. But before you do that, let's "drill" down to the Registry that goes by the name of HKEY_CLASSES_ROOT\Folder\shell, by clicking on the plus sign beside the name of those HKEYs and subkeys.
When you've arrived at our destination, you should see at least two subkeys hiding beneath HKEY_CLASSES_ROOT\Folder\shell. One should be named Open, the other Explore. Yes, there they are -- the keys that cause "Open" and "Explore" to appear in each folder's context menu!
To add new choices to the folder context menu, just add new subkeys. Here are three easy steps:
Can expanding the Folder's context menu be this easy? Is that all there is to it? The short answer is yes. Adding a new context menu choice is just that easy!
Of course, a new menu choice is of little value, all by itself. What happens when you select our new menu choice? At the moment, nothing.
Now come on. You knew it all along. Nothing is as easy as 1, 2, 3, at least where are computers are concerned. There must be steps 4, 5, and 6. But these remaining steps are pretty easy. So let's take them now.
First, we must add one more subkey key to the Windows Registry. It must be named "command," and reside immediately beneath the one we added a moment ago. To those who don't know him well, the subkey's full name is:
HKEY_CLASSES_ROOT\Folder\shell\Print with DirPrn\command.
This creates a place to store the command to be run whenever our new menu choice is selected. To store the command itself, shift your gaze to the right-hand pain of RegEdit's window. There you should see line reading "(Default) REG_SZ," indicating that the new subkey's default storage location could contain a string (type REG_SZ), but is currently empty.
To fill this location with our command, just double-click on the word "(Default)", or click on it once and select Modify from RegEdit's Edit menu. Either way, you'll then see a small dialog box allowing you to enter the default location's new value. For our purposes, the value should be a command that will run our Directory Printer, something like:
C:\Program Files\DirPrn\DirPrn.exe %1
The actual path to the Directory Printer program (DirPrn.exe) may be different on your computer. Be sure to use the correct path, or our new command will fail. And don't forget to add the " %1" after the full path of the program. That's a "placeholder," showing Windows where to insert the name of the directory to be printed.
Once this data value has been entered, you're done! You can test your work by right-clicking on any of your computer's folder icons. When you see the context menu choice that reads "Print using DirPrn," select it. The Directory Printer will find the selected directory's name within its command line, and immediately display this directory in its main window, ready for printing.
Let Karen Do It
Those of you who like spelunking in the Registry will probably delight in following the steps outlined above. But the more sensible among us, those who prefer not to crawl on our bellies for hours through the ones and zeros left behind by the Registry's countless spooky residents, would rather have this job done for us. What we want -- no, need -- is a program to do our dirty work.
Fortunately, the latest version of Directory Printer comes to our rescue. Its main window now sports a checkbox reading "Add 'Print with DirPrn' to file and drive context menus." Place a checkmark here, and the Directory Printer will make all the necessary changes to the Registry for you.
In fact, it not only adds "Print with DirPrn" to each folder's context menu, it also adds this choice to the context menu that appears above each drive's icon. This is accomplished by making changes to the HKEY_CLASSES_ROOT\Drive\shell directory branch.
The new Directory Printer knows some other tricks too. Now, it will print a drive's volume name and serial number at the top of each page, in addition to the information it printed there before (user name, date, time, etc.). This is great if you often print the contents of removable media, such as diskettes or CD-ROMs.
The latest version also fixes a bug that appeared briefly last week. For several hours, the Web site had version that wouldn't print directory subtotals when run under Windows 95, 98, or Windows NT. That's because I inadvertently used a Windows API function only supported by Windows 2000. <blush>
I've also improved the way the Directory Printer handles security violations (files that the current user is not allowed to open). The new version can also record each file's time of creation and last access, whether printing the report, or saving it to disk.
If you'd like to give this new version (v2.9) a try, drop by my Web site at https://www.karenware.com/powertools/ptdirprn.asp. As always, the program, and its Visual Basic source code are free. And this time, you might want to download the latest Visual Basic runtime while you're there. Microsoft updated this collection of files last week, and my Web site now offers this new version (6.0, Service Pack 4).
Next week I'm loading up the Power Tools workshop, and going on a 10-day trip through Missouri, Illinois, Kentucky, and Ohio. So the next time we talk, I'll be writing to you from the Ohio shore of sunny Lake Erie. Until then, as always, if you see me on the road or on the 'net, be sure to wave and say Hi!