• Create BookmarkCreate Bookmark
• Create Note or TagCreate Note or Tag
• PrintPrint

### 4.3. File Types: The Link Between Documents and Applications

The term File Types describes the collection of associations between documents and the applications that use them. The most apparent use of this feature is that, for example, Windows knows to run Notepad when you double-click on a text document in Explorer (proof that Windows XP is not truly object oriented).

True object-oriented design dictates that objects (in this case, files and folders) be aware of their own traits. This design is only mimicked in Windows XP. Instead of each file's knowing which application is used to edit it, Windows determines how to handle a file based solely on the filename extension. This design has advantages and disadvantages, but Microsoft's decision to hide filename extensions, the basis for file associations, only makes the whole system more difficult to understand and master.

It all starts with file extensions, the letters (usually three) that follow the period in most filenames. For example, the extension of the file Readme.txt is .txt, signifying a plain text file; the extension of Resume.wpd is .wpd, signifying a document created in WordPerfect. By default, Windows hides the extensions of registered file types in Explorer and on the desktop, but it's best to have them displayed.

File extensions not only allow you to easily determine what kind of file a certain file is (because icons are almost never descriptive enough), but also allow you to change Windows' perception of the type of a file by simply renaming the extension. Note that changing a file's extension doesn't actually change the contents or the format of the file, only how Windows interacts with it.

To display your file extensions, open Folder Options in Control Panel (or from Explorer's Tools menu), choose the View tab, and turn off the Hide extensions for known file types option. Click OK when you're done.

By hiding file extensions, Microsoft hoped to make Windows easier to use—a plan that backfired for several reasons. Because only the extensions of registered files are hidden, the extensions of files that aren't yet in the File Types database are still shown. What's even more confusing is that, when an application finally claims a certain file type, it can appear to the inexperienced user as though all of the old files of that type have been renamed. It also creates a "knowledge gap" between those who understand file types and those who don't; try telling someone whose computer still has hidden extensions to find Readme.txt in a directory full of files. Other problems have arisen, such as trying to differentiate Excel.exe and Excel.xls in Explorer when the extensions are hidden; one file is an application and the other is a document, but they may be otherwise indistinguishable.

A context menu (sometimes called a shortcut menu) is the little menu that appears when you use the right mouse button to click on a file, folder, application titlebar, or nearly any other object on the screen. Most of the time, this menu includes a list of actions appropriate to the object on which you've clicked. In other words, the options available depend on the context.

The context menu for files, the most commonly used and customized context menu, depends upon the type of file selected, which is determined by the filename extension. For example, all text files (with the .txt extension) will have the same context menu, regardless of what they contain or which application was used to create them. (This is why Windows gives you a stern warning when you try to change a file's extension.)

In addition to the standard context menu items, such as Copy, Paste, Delete, Rename, and Properties, you'll usually see Open, Print, and Print To (at the top of the list), which represent customizable actions that can be performed with the selected file. Each of these actions is linked to an application: if you right-click on a .txt file and select Open, Windows will launch Notepad (by default) and instruct it to open the selected file. Customizing this association between the document type and the applications installed on your computer is what this section is about.

The default action—the action that is carried out when a file of a given type is double-clicked—appears in bold text in the context menu. If a file type is not registered with Windows, double-clicking on a file of that type will open the Open With dialog box, allowing you to choose an associated application on the spot. The exception to this occurs when a file type has been registered, yet has no actions associated with it (useful if you want to identify a file type, but not necessarily open it ).[3] In this case, nothing will happen when the file is double-clicked.

[3] An example is the way DLL files are registered with Windows by default.

The default action is also what can cause the most controversy. Say you have grown accustomed to double-clicking .html files on your hard disk and having them opened in Netscape Navigator (in other words, Netscape is the default application for that file type). One day, out of necessity or obligation or whatever, you install one of Microsoft's updates to Windows, which happens to contain a new version of Internet Explorer. Unless you're careful to choose the correct advanced options, suddenly, and without warning, all of your .html associations are changed, making Internet Explorer the default application.

Although the most obvious reason to customize a file's context menu is to control the default action, what makes context menus so useful is that you can assign as many different actions as you like to any given file type. In the case of .html files, for example, you could add an Edit action to open your favorite web page editor, a View with Netscape action, and a View with Internet Explorer action—all in addition to the default action.

It's possible to add, remove, or modify context menu items for nearly any file type. The File Types window, shown in Figure 4-7, is the only dedicated tool provided by Microsoft to manage file associations in Windows; it has been somewhat improved in Windows XP from previous versions. Some thought has been given to both experienced and novice users, although it still lacks the streamlining and advanced functionality such an important feature deserves.

##### Figure 4-7. The File Types tool has been significantly improved in Windows XP from previous versions, although it has some very annoying quirks.

For the most flexibility in customizing context menus, you'll want to see how file associations are actually stored in the Registry, as described later in this chapter.

##### 4.3.1.1. Use file types to add, remove, or edit context menus
1. Select Folder Options from Explorer's View menu (or double-click the Folder Options icon in Control Panel), and choose the File Types tab.

The list shows all of the file types that have been configured on your system. You can sort the entries by filename extension or file-type description to make any given file type easier to find by clicking the respective column headers.[4]

[4] The ability to sort the entries is a relatively new and sorely needed feature. In earlier versions of Windows (before Windows Me), finding file types in this window has been difficult: for example, the entry for the .xls extension was listed under "Microsoft Excel Spreadsheet," putting it alphabetically under "M" instead of "E" for Excel or "X" for XLS.

Keep in mind that some file types may be claiming more than one extension. For example, the .htm and .html extensions are most likely associated with the same file type. If you are editing such a file type, it won't matter which extension you select. See Section 4.3.1.2 later in this chapter for more information.

2. Select a file type from the list, and click Advanced. Don't bother with the Change button; it only displays the more limited Open With dialog box, discussed in "Choose a file-type association on the fly," later in this section.

If you see Restore here instead of Advanced, see "What to do when the Advanced button is missing," also later in this section.

3. The Actions list, shown in Figure 4-8, contains a list of the customizable context menu items for the selected file type. Each one has a name and a command line (the application filename followed by command-line parameters, if applicable).

##### Figure 4-8. The Edit File Type window shows the customizable actions (each of which appears as a context menu item) for any given file type.

The bold item is the default action, also shown in bold at the top of the context menu. If there's no bold item, and therefore no default, double-clicking a file of that type will probably do nothing. The exception is if one of the actions is named open, it will be the default whether or not it appears in bold.

To make no action the default, you'll have to delete the current default (bold) action. If you don't want to remove any actions, just add a new, temporary action, make it the default, and then delete it. You might wish to have only non-default actions for a file type if you want to prevent accidental activation.

The Use DDE option, if enabled, means that the action is intended to activate an already-running instance of an application (if possible), rather than starting a new instance. DDE is a poorly documented yet important feature used by Windows to communicate with applications that are already open; for example, if you right-click on or more Microsoft Word Documents (.doc files) and select Print while Word is already running, Windows simply uses DDE to communicate with Word and instruct it to open the file.

4. Click OK when you're done. The changes should take effect immediately; your desktop and any open Explorer or single-folder windows should automatically refresh within a few seconds.

In some cases, your changes will not take effect in any open Explorer windows. If, for example, you rename an existing file type or change its icon, and the old information still appears in file listings when you're done, just close the Explorer window and then re-open it to force it to utilize your new settings.

##### 4.3.1.2. Link a filename extension to an existing file type

Sometimes two filename extensions share the same file type—that way, you don't have to go to the trouble of creating and modifying a separate set of actions for each extension. In cases where two file formats are similar enough to warrant file-type sharing, such as .jpg and .jpeg files, or even .jpg and .gif files, follow the upcoming steps.

To see a list of all the extensions owned by a given file type, sort the Registered file types list by file-type description by clicking on the respective column header. Note that it's possible for two different file types with a different set of actions to have the same description, which would unfortunately make then indistinguishable in this view.

1. In the File Types window (discussed earlier in this section), configure a single file type as desired (or simply locate an existing file type).

2. Click New, and type the filename extension without the dot (e.g., txt) in the File Extension field. If the extension is currently associated with another file type, that link will be broken, then replaced with the one you choose here.

3. Click Advanced >> to show a second list of existing file types, and choose any desired file type to claim ownership of the new extension.

If, instead, you want to create a new file type, either choose <New> or simply make no choice from the list. A new file type will be created and named for the extension; if you type xyz, the new file type will be named "XYZ File."

4. You can then proceed to edit the new entry. If you've linked the new extension with an existing file type, all that file type's properties (e.g., actions, icon, description) will appear in the new entry as well.

##### 4.3.1.3. Choose a file-type association on the fly

If you have double-clicked on a file with an extension that has not yet been registered, you might have seen the dialog box shown in Figure 4-9, which is Windows' way of asking what to do with the selected file. Here, you have two choices:

##### Figure 4-9. Double-click a file of an unknown type (unfamiliar filename extension), and Windows will display this dialog asking what to do.

Use the Web service to find the appropriate program

This option jumps to a page at Microsoft's web site, which is used to look up the extension of the selected file to give you a clue as to what type of file it might be. See the "Microsoft Extension Finder" sidebar for details.

## Sidebar 1. Microsoft Extension Finder

Microsoft has put together a simple "extension finder" web site, intended to provide more information about file types that Windows doesn't recognize. Unfortunately, it's only available through the interface for unregistered file types, but you can go directly to this URL to look up any filename extension:

http://shell.windows.com/fileassoc/0409/xml/redir.asp?Ext={yourextension}

where {your extension} is the filename extension (without the dot) that you wish to learn more about. For example, to find out about the .sit extension, you'd go to:

http://shell.windows.com/fileassoc/0409/xml/redir.asp?Ext=sit

The resulting page typically includes a description of the file format and links to one or more applications that can be used to view or edit files of the requested type.

Select the program from a list

In most cases, you'll want to use this option to choose an application you've already installed to open the document. The subsequent solution shows how to do this for file types that have already been registered.

This is the same box that appears if you open the File Types window, select a file type from the list, and click Change. To get this window for an already registered file type without having to open the File Types window first, follow these steps:

1. Right-click the document you wish to open and select Open With.[5]

[5] Previous versions of Windows required that you hold the Shift key to display the Open With item, a step no longer necessary in Windows XP.

You can also right-click the file and select Properties to see which program is configured as the default for the type. You can then click Change to then display the Open With dialog.

2. The Open With dialog appears, as shown in Figure 4-9. Choose an application from the list, or click Browse if the desired application is absent.

3. Click Always use this program to open these files to assign a new default action using the selected application. This option will be turned off by default, allowing you to choose an application without affecting your current associations. Unfortunately, there's no way to add a non-default context-menu item with this method.

This is a quick way to not only create new file types on the fly, but change an existing file type without having to return to the File Types window. It's important to realize, however, that when you change an existing file type's default action using this method, Windows XP considers the change to be tentative, and displays different controls the next time you view the file type. See the following topic, "What to do when the Advanced button is missing," for details.

##### 4.3.1.4. What to do when the Advanced button is missing

Occasionally, the Advanced button in the File Types window will be replaced with a Restore button for a given file type. This is the result of a new built-in mechanism for restoring file types that have been overwritten with the "Choose a file-type association on the fly" procedure, explained earlier in this section. Unfortunately, this mechanism doesn't work very well, and ends up causing more frustration than it would if it were not present at all.

The problem is that if the Restore button is present, there's no way to edit a file type without first completely reverting it to its earlier configuration.

The cause is the way file type information is stored in the Registry when the default action is modified by using Open With—instead of overwriting the existing file type data (explained in detail in Section 4.3.2, later in this chapter), the new association is written to this Registry location instead:

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\
Explorer\FileExts\{your file extension}

So, for example, if you're editing the .asp file type, and the Registry key, HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.asp, exists, the File Types window will display the Restore button. If you delete the key, the Restore button will go away, but the new file type data will be lost as well. Since it would be too much trouble to move the relevant Registry data to its more permanent location, there's unfortunately no practical way to get the Advanced button back without first reverting the file type. Let's hope Microsoft fixes this in the next version.

#### 4.3.2. Understanding File Types

All active file type associations are stored in the Registry. Understanding the structure of file type data can be very helpful in not only fixing problems, but performing advanced techniques (illustrated later in this chapter). Examples include backing up your file types and modifying otherwise inaccessible file types, such as drives and folders.

The HKEY_CLASSES_ROOT branch of the Registry stores information on all your file types. File extension keys (preceded by periods) are listed first on the tree, followed by the actual file type keys.

The first Registry keys, named for file extensions, typically only contain pointers to other keys, which then describe the file types. For example, if you navigate to the key HKEY_CLASSES_ROOT\.txt (note that the period is included here), you'll notice that there's not a lot of information there. The important (and often sole) piece of information is the (default) value, which is set to the name of another key, located lower down the tree.[6] In the case of .txt, the (default) value contains only the text txtfile (see Figure 4-10). This, in effect, is a reference to HKEY_CLASSES_ROOT\txtfile, which is the key that contains the actual information for file type, as shown in Figure 4-10.

[6] The reason the other keys appear lower down on the tree is merely due to alphabetical sorting.

##### Figure 4-10. The Registry key named for the filename extension contains a pointer to another Registry key (see Figure 4-11).

All of the details of this file type are stored in the txtfile branch, such as the formal name shown in the Type column in Explorer (in this case, "Text File"), the icon used for all files of this type, and the applications used to open the file. Many different extension keys can point to this branch, so a single file type like txtfile can have many filename extensions associated with it. This architecture can make it a little tricky to understand the way file types are stored in the Registry, but it does afford a fairly flexible system of file associations.

##### Figure 4-11. The second Registry key contains the file-type information; several file extension keys can point to this key.

The structures shown in Figure 4-10 and Figure 4-11 illustrate the two Registry branches that make up a typical file type. File types can be created by application installers, through changes made in the File Types window (explained earlier in this section), or even manually by editing the Registry directly. A bunch of file types are also set up automatically when Windows is first installed.

First, a key is created that is named for each extension associated with the file type (usually only one, for starters).[7] The (default) value of this key contains the name of the file-type Registry key; it does not contain the full Registry path, however, nor does it contain the formal name of the file type (shown in Explorer). For example, put txtfile here and not Text File. The Content Type value shown in Figure 4-10 may appear for some file types, but is not necessary for normal operation.

[7] An example of a file type with two or more extensions is the HTML file type (used by web browsers), typically associated with .html, .htm, .shtml, and .shtm files.

A key called ShellNew may also appear underneath the file extension key. The existence of this key tells Windows to include the extension in Explorer's New menu (discussed earlier in this chapter), allowing the user to create a new, empty file of that type without having to open an application. The reason that the ShellNew key is located underneath the extension key and not the file-type key (discussed later in this section) is that a file type may have more than one extension, and Windows needs to know which extension to use when creating a new file. The ShellNew key is usually empty, although there may be a value called FileName that points to a template file, a file on your hard disk that Windows will use to create a new, blank document (stored, by default, in \Documents and Settings\{username}\Templates). In most cases, the FileName value is omitted, and Windows will create a zero-byte (empty) file with the appropriate extension.

Most of a file type's definition is located in the main file-type key, the name of which is specified in each of the extension keys listed earlier. In Figure 4-11, the txtfile key contains the rest of the settings for the Text File file type. First of all, the (default) value in this key specifies the formal, aesthetic name of the file type—the text that appears in the File Types dialog box in Explorer and in the Type column in Explorer's Details view (e.g., "Text File").

If the value named AlwaysShowExt is present in this key, the extension for this file type will be displayed in Explorer, even if the user has elected to hide extensions for file types that are registered (a setting described at the beginning of this section). A related value, NeverShowExt, appears in a few file type keys, such as those for Windows Shortcuts (.lnk files), Internet Shortcuts (.url files), and Explorer Commands (.scf files), and means that the extensions for these types are never shown, even if the user has elected to show all extensions. Simply delete the NeverShowExt value to instruct Explorer to show the filename extension for the corresponding file type.

You may also see a binary or DWORD value entitled EditFlags, which instructs Windows what is allowed and what is not in the File Types window. See Table 4-1 for some of the possible values and their meanings. Feel free to change or simply remove this value to allow changes to a particular File Type. Unfortunately, these restrictions only apply to the File Types window, and don't prevent other applications from changing your file types.

##### Table 4-1. Some of the possible values for EditFlags and what they mean
EditFlags bit[8] Meaning
00 00 00 00(or omitted) No restrictions
01 00 00 00 Not shown in the File Types window at all
02 00 00 00 Change button disabled in File Types window
08 00 00 00 Advanced button disabled in File Types window
00 01 00 00 Can't change file type description in Edit File Type window
00 02 00 00 Change Icon button disabled in Edit File Type window
40 00 00 00 Edit button disabled in Edit File Type window
80 00 00 00 Remove button disabled in Edit File Type window

[8] EditFlags values can be added to implement several restrictions; for example, an EditFlags value of 00 03 00 00 will disable the description field and Change Icon button in the Edit File Type window.

In the file-type key are three or four independent subkeys. DefaultIcon contains only the (default) value, set to the filename of the file containing the icon used for the file-type. Icons are specified by filename and icon index, separated by a comma; for example, c:\windows\system32\shell32.dll,152 specifies the 153rd icon in the shell32.dll file. The specified file can be any .ico or .bmp file, as well as an .exe or .dll file containing one or more icons. To use the first icon in the file, omit the number or specify 0 (zero); use 1 (one) for the second icon, and so on. The easiest way to choose an icon is with the File Types dialog box in Explorer, which will allow you to browse and choose icons without typing or guesswork.

 Internet Shortcuts don't launch applications directly; instead, they redirect the URL contained therein to Windows, which then delegates the task to an application suitable to the particular type of URL (e.g., web browser for http:// addresses, FTP client for ftp:// addresses, etc.). As part of this design, you won't be allowed to change the icon for Internet Shortcuts, even if you delete the EditFlags value (explained earlier in this chapter). To fix this, you'll have to delete the IconHandler key, located in the shellex branch, as well.

Most of the meat of the file type is stored in the shell key. Its subkeys define the actions, or what happens when a file of this type is double-clicked and which commands appear in the file type's context menu (explained earlier in this section). Underneath shell is a separate key for each command shown in the context menu; that is, when you right-click on a file of this type, these are the commands that will appear at the top of the list. Most file types have an Open command (with a key by the same name). You may also see Edit, Print, PrintTo, Play, and View here. You can add, remove, or change any of these commands you wish. In each one of these keys is a key called command. Each command key's (default) value is set to the application filename used to carry out the respective command. Figure 4-10 and Figure 4-11 illustrate this structure in particular.

For example, if Notepad is associated with the Open command for text files, the contents of HKEY_CLASSES_ROOT\txtfile\shell\open\command will be:

Notepad.exe "%1"

Now, the "%1" (including the quotation marks) is very important—%1 is where Windows substitutes the full path and filename of the clicked file, and the quotation marks are necessary in case there are any spaces in the filename of the clicked file. So, if you were to right-click on any file with the .txt extension (say, c:\documents\my file.txt) and select Open from the context menu that appears (see Figure 4-12), Windows would carry out the command:

Notepad "c:\documents\my file.txt"

which will launch Notepad and instruct it to open the document.

##### Figure 4-12. A context menu for the bitmap file type shows the default Preview option, as well as the extra Edit and Power Rename options.

While there can be several available commands for any given file type, only one of the commands will ever appear in bold. This command is called the default and is the one that Windows uses when you double-click on a file instead of right-clicking. Usually, Open is the default, but any existing command can be set as the default.[9] To make a different command the default, specify the name of the command in the (default) value of the shell key. For example, if a file type contains Open, Edit, and Print, and you type edit in shell's (default) value, the Edit command will appear bold in the file type's context menu, and Edit will be the command carried out when you double-click. If the (default) value is empty, the Open command (if present) is assumed to be the default.

[9] Note that although the word open is often spelled with all lower-case letters in the Registry, it still appears capitalized in the context menu. Windows will preserve the case of all other commands as you've typed them, but will automatically capitalize Open.

The shellex key contains references to shell extensions, programs designed to work especially with context menus. These are never shown in the File Types window but are nonetheless very important, and it can be very handy to be able to modify or remove them. For example, the Power Rename command shown in Figure 4-12 is a shell extension. Unless you're able to write and compile DLLs, however, you won't be able to create new shellex entries. However, you can remove some unwanted context menu commands and extra tabs in property sheets of certain file types by removing the corresponding shell extension keys here. I don't have to tell you that it's a good idea to back up any file-type key with a Registry patch before you make any changes.

You might also see a key named CLSID in various parts of file-type keys; these are merely pointers to registered application components. To find out what a particular entry means, copy the CLSID code to the clipboard (hit F2 to rename, Ctrl-C to copy, and then ESC to abort the renaming process), and then search the Registry for other references to it.

Lastly, you may see a ddeexec key, which contains DDE commands and associated data. DDE is used to communicate with running applications, and is discussed earlier in this section.

The next few solutions in this chapter illustrate some of the ways you can use the file type Registry entries to accomplish things otherwise not possible.

#### 4.3.3. Protect Your File Types

One of the most aggravating aspects of using Windows is when the settings you've spent time customizing are overwritten or simply forgotten. Sometimes this is the result of a bug, but often, and especially in the case of file types, there's more to it. Some software developers jerryrig an application so that it overwrites your file associations, either when it's first installed or, even worse, every time the program runs. That way, their program becomes the default whether you like it or not.

For some proprietary file types, such as Excel Files (.xls), this isn't much of a problem, because there really aren't any other programs that use these files. The impact is greater on more general file types, such as the large quantity of graphics formats (.gif, .jpg, .tif, .bmp, and .png ), where there are literally hundreds of applications that use these files. It's not unusual for several of these applications to be installed simultaneously on a single system, all competing for the dubious distinction of being the default. Probably the most high-profile example of this competition is that between competing web browsers; not only are file associations in play, but URL associations as well—every time you open an Internet Shortcut or click a web link in any application, the URL association is what's used to decide which web browser application to use.

Ideally, only you should be in the position to decide which program you use for each task. Unfortunately, it's essentially impossible to write-protect (prevent the overwriting of ) any Registry settings—including file types—in Windows XP. Although it's possible to set user permissions for various Registry keys (see Chapter 8), this only restricts access for programs run by other users.

Probably the most effective protection against overwriting file types is to back up the portions of the Registry that are at risk, allowing you to easily restore them should the need arise. This is accomplished with Registry patches; see Section 3.2.1 before continuing.

The procedure outlined here would be a good one to follow, for example, before installing an application you believe might overwrite an existing file type. Repeat these steps for each file type you wish to protect:

1. Open the Registry Editor (discussed in Chapter 3).

2. Expand the HKEY_CLASSES_ROOT\ branch, and locate the keys that you wish to protect.

Any given file type is stored as one or more extension keys and a file-type key. For example, the extensions .txt and .log may both be linked with the txtfile file type. So, to save the entire file type, you'll need to save each of the following Registry branches:

HKEY_CLASSES_ROOT\.txt
HKEY_CLASSES_ROOT\.log
HKEY_CLASSES_ROOT\txtfile

If you only save the extension keys or the file-type key, the Registry patch will be incomplete. See Section 4.3.2, earlier in this chapter, for details on this structure.

To see a list of all the extensions owned by a given file type, open the File Types window (see Section 4.3.1 earlier in this chapter), and sort the Registered file types list by file-type description.

3. When you've highlighted a Registry key you want to export, select Export Registry File from the Registry menu, and specify a filename for the patch. Because you'll be exporting at least two patches, don't worry too much about the filenames just yet. Just make sure not to export two branches to the same file, however, as one will simply overwrite the other.

Also, don't try to export the entire HKEY_CLASSES_ROOT branch, because it contains much more information than we need for this purpose, and restoration of a patch will have unpredictable effects.

4. You can only export one key at a time, so start with one and repeat step 3 for each remaining key. Once you've exported all the keys you're interested in, close the Registry Editor.

5. You should have at least two Registry patches from this exercise, perhaps more. Because they're just plain text files, we can easily merge them together into a single file with Notepad. Choose one file to be the main patch, and then cut and paste the contents of the other patches into it. The only editing you'll have to do is to remove the Windows Registry Editor Version 5.00 line from all but the main patch, so that it only appears once—at the top of the file.

If you're exporting multiple complete file types, you might want to merge the individual patches into several separate Registry patches—one for each file type.

6. Whenever a particular file type that you've backed up becomes overwritten by an errant application, just double-click the patch you made to restore it.

In most cases, when you apply a Registry patch, it will simply overwrite the information that's there with whatever is in the patch. However, since applying registry patches merges their information with what already may be in the registry, there may be leftover context-menu items from any newly installed applications.

7. To apply the patch automatically whenever you start Windows, create a new Windows Shortcut in your Startup folder (usually \Windows\Start Menu\Programs\Startup), and type the following into the shortcut's command line:

regedit /s "filename"

where filename is the full path and filename of the Registry patch you wish to apply (e.g., c:\filetypes\text.reg); the quotation marks are included to accommodate any spaces in the file or folder names. Note the /s switch, which runs the Registry Editor in silent mode, skipping the two prompts that normally appear when Registry patches are applied.

Although there's unfortunately only so much you can do to prevent your file types from being overwritten, other workarounds do exist. Try adding a context menu item for each program installed on your system, such as "Open with Notepad" and "Open with WordPerfect" for text files. That way, whatever the default is, you'll always have your preferred applications handy.

One sticking point you may encounter when trying to reconfigure file types is that some actions use Dynamic Data Exchange (DDE). DDE is a method of communication between applications, sometimes used by Windows to communicate with the applications it launches, and is discussed earlier in this section. If a particular file type for an application stops working for some reason, it could be that the DDE information has changed or been erased altogether. If this is the case, you'll usually have to reinstall the application to restore the DDE-enabled file types, because there's little standardization with DDE. Often, however, simply deactivating the Use DDE option in the Editing action for type window is enough to fix the problem.

#### 4.3.4. Customize Context Menus for Drives, Folders, and Desktop Icons

Folders, drives, and desktop icons also have customizable context menus, but the File Types window (described earlier) has limitations on what can actually be changed. Refer to Section 4.3.2, earlier in this chapter, for more information on the Registry structure involved in this solution:

1. Open the Registry Editor (discussed in Chapter 3).

2. The Registry key you'll need to open depends on what object you're customizing:

1. For folder context menus, expand the branches to HKEY_CLASSES_ROOT\Directory\shell\.

2. For drive context menus (visible in Explorer and the My Computer window), expand the branches to HKEY_CLASSES_ROOT\Drive\shell\.

3. For the context menus of any system objects, such as My Network Places, expand the branches to HKEY_CLASSES_ROOT\CLSID\{class id}\shell\, where {class id } matches one of the codes listed in Chapter 3, including the braces.

3. Select New from the Edit menu, select Key, type the name of the new item you want added to the list, such as Open or Edit, and press Enter.

4. Highlight the new key, select New from the Edit menu, and then select Key again.

5. Type command for the name of this new key, and press Enter.

6. Double-click the (Default) value in the right pane, and type the full command line (path and filename of the application executable, followed by any applicable command-line parameters) you want associated with this entry.

7. Close the Registry Editor when you're finished. These changes should take effect immediately.

#### 4.3.5. Print Out a Folder Listing

What would seem to be a simple function, the ability to print out a list of files in any given folder, does not exist in Windows XP. However, there is a way, using folders' context menus, to add this functionality to Windows.

1. Open the Registry Editor (discussed in Chapter 3), and expand the branches to HKEY_CLASSES_ROOT\Folder\shell.

2. Select New from the Edit menu, select Key, and type Print Contents for the name of this new key.

3. Highlight the new Print Contents key, select New from the Edit menu, select Key again, and type command for the name of this new key.

4. Double-click the (Default) value in the right pane, and then type the following:

cmd.exe /c dir "%1" > PRN

This line launches the cmd.exe application (also known as the Command Prompt, discussed in Appendix C), and then, using the /c parameter, instructs it to carry out the following command:

dir "%1" > PRN

which generates a folder listing[10] and sends it to the printer object (PRN). You can use any of the dir command's optional parameters to further customize the listing it generates. For example, to specify the desired sort order, change the above to the following:

[10] See the discussion of file types, earlier in this chapter, for an explanation of "%1" as it is used here.

cmd.exe /c dir "%1" /o:xxx > PRN

where xxx can be any or all of the following letters, in order by preference: N to sort by name, E for extension, S for size, D for date, G to group directories first, A by last access date (earliest first). See Appendix C for more information on the DIR command.

5. If you wish to send the folder listing to a text file in the folder, navigate to HKEY_CLASSES_ROOT\Folder\shell\Save Contents\command (create the missing keys just like in steps 2 and 3), and then type the following for the command key's (Default) value:

cmd.exe /c dir %1 > "Folder Listing.txt"

6. Close the Registry Editor when you're done; the change will take effect immediately. Just right-click any folder and select Print Contents to send the contents of the selected folder to the default printer.

Creative Element Power Tools (available at http://www.creativelement.com/powertools) comes with several similar context-menu add-ons, allowing you to print or copy a folder's contents to the clipboard, among other things. See Windows XP in a Nutshell (O'Reilly) for extensive coverage of batch files and DOS commands such as dir.

#### 4.3.6. Turn File Icons into Thumbnail Previews

Windows tries hard to be as graphical as possible, which can sometimes be its downfall. Case in point: when was the last time you found the icon for an application or associated document to be the least bit helpful in determining what was inside?

In Explorer, when you view a folder containing icons (.ico files), cursors (.cur files), or animated cursors (.ani files), their file icons are previews of their contents instead of simply generic icons for the application with which they're associated. Now, Windows has the capability to generate these types of thumbnail previews for other kinds of files as well, and a special feature in Windows XP takes it even further.

##### 4.3.6.1. Solution 1: Icon previews for bitmap (.bmp) files

The advantage of this solution is that once the change has been made, it will be enabled automatically for all folders on your system. The disadvantages are that this solution works only for .bmp files, and the thumbnail previews will never be larger than the rest of your system icons (usually 32 X 32 pixels):

1. Open the Registry Editor discussed in Chapter 3.

2. Expand the branches to HKEY_CLASSES_ROOT\Paint.Picture\ DefaultIcon.

3. Change the (Default) value to %1. If the .bmp file type is no longer associated with MS Paint, the correct Registry location will be somewhere other than in Paint.Picture. Try looking in the (Default) value of HKEY_CLASSES_ROOT\.BMP for the current file type (see Section 4.3.2, earlier in this chapter, for more information).

4. Close the Registry Editor and press F5 to refresh any open windows to reread the icons for bitmap files. If it doesn't work right away, you might have to close any open Explorer windows and re-open them for the change to take effect.

To increase the size of icons, double-click the Display icon in Control Panel, choose the Appearance tab, and click Advanced. Select Icon from the Item menu, and type in a larger value for the size, such as 48 or 64. Note that this will make all icons on your system (those on the desktop, and in the Large Icons display in Explorer) larger.

##### 4.3.6.2. Solution 2: Use built-in icon previews for all graphic files

The advantages of this solution are that it works for more file types, including .bmp, .jpg, and .gif files, and that the previews can be larger than normal icons. The disadvantages include that the option needs to be enabled for each folder you view (you wouldn't want to set it as the default). Also, it's a pretty clumsy interface, and image files that it doesn't understand are shown simply with their standard file icons rather than being hidden. If you are viewing a folder containing more than just image files, the display is less than ideal.

Open Explorer, and locate any folder that contains at least one graphic image file (.jpg, .gif, or .bmp). Select Thumbnails from the View menu (this option may not be available if you have Internet Explorer integration disabled—see Chapter 8). Select one of the other view modes (such as Details or Large Icons) to restore the display to normal.

If you've configured Explorer to display hidden files, you'll notice a new hidden file, thumbs.db (which contains the thumbnail data), in any folder you view. As long as this file is present, the folder's view will always be set to Thumbnails. If you delete this file, and then re-open the folder, it should revert back to the standard Details or Large Icons view.

If you need a better thumbnail preview, try a third-party application, such as ACDSee-32 (http://www.acdsee.com/). It not only has a far-superior thumbnail viewer, but is a much better and faster image viewer than the Windows Picture and Fax Viewer (discussed later in this chapter).

#### 4.3.7. Disable the Automatic Display of Thumbnails in Certain Folders

One of the new marketing gimmicks Microsoft is using to promote Windows XP is that it is supposedly "task oriented," which means that the design elements are first and foremost designed to help accomplish tasks. Unfortunately, this is more lip service than anything else; most of the time, Windows XP tends to be more component-oriented than task oriented. What Microsoft is actually referring to is the added assumptions Windows makes, many of which are just plain wrong and end up simply annoying us.

For example, if you view certain folders (such as My Pictures) in Explorer or the File Open/Save dialog, its contents will be shown using the Thumbnails view instead of the standard List or Details views. Although you can manually switch the view each time you open the folder, there are several ways to turn it off.

##### 4.3.7.1. Solution 1: Modify the assumptions made about a given folder
1. Right-click on any given folder icon, and select Properties.

2. Choose the Customize tab, and choose Documents (for any file type) from the list.

3. Click OK when you're done. You'll probably have to close the folder and re-open it for the change to take effect.

This feature should be available for every folder on your system except your system folders. Unfortunately, you can't customize system folders (such as My Pictures), so you'll have to settle for one of the remaining solutions.

##### 4.3.7.2. Solution 2: Change the way thumbnails look (requires TweakUI)
1. Open TweakUI (see Appendix A).

2. Expand the Explorer category branch, and select Thumbnails.

3. Change the value of Size to 32.

Unfortunately, this won't disable the thumbnails, but it will make them the same size as standard icons. The result is a less cumbersome and easier to use interface, but it's not perfect. See the following solution if this isn't suitable.

##### 4.3.7.3. Solution 3: Relocate your system folders
1. Open TweakUI (see Appendix A).

2. Expand the My Computer category branch, and select Special Folders.

3. Change the locations of the special folders (such as My Pictures) you wish to have point to different locations. This lifts the restriction noted in Solution 1, earlier.

While this returns the display of your folders to the standard icon view, it does cause any applications that default to your My Pictures folder (when using File Open/Save dialogs, for instance) to look in a different location, which means that you'll have to manually navigate to the desired folder each time. See Section 4.4.3, later in this chapter, for a further workaround.

#### 4.3.8. Turn off the Windows Picture and Fax Viewer

The Windows Picture and Fax Viewer is set as the default image viewer for all sorts of file types in Windows XP. Unfortunately, choosing another program as the default in the File Types window (described earlier in this chapter) won't change this, and there's no option in the interface that can disable this component. It's a really stupid design, and it takes a Registry change to fix it:

1. Open the Registry Editor (discussed in Chapter 3).

2. Expand the branches to HKEY_CLASSES_ROOT\SystemFileAssociations\image\ShellEx\ContextMenuHandlers.

3. Delete the ShellImagePreview key.

4. Close the Registry Editor when you're done; the change will take effect immediately.

• Create BookmarkCreate Bookmark
• Create Note or TagCreate Note or Tag
• PrintPrint