InformIT

Mastering File Types in Windows XP

Date: Nov 4, 2005

Sample Chapter is provided courtesy of Sams.

Return to the article

Microsoft offers scant documentation and tools for working with file types in Windows XP, presumably to protect the sensibilities of the novice user. Ironically, however, this just creates a whole new set of problems for beginners, and more hassles for experienced users. This sample book chapter remedies that situation. You'll learn the basics of file types, and then see a number of powerful techniques for using file types to take charge of the Windows XP file system.

in this chapter

Amazingly, a long list of useful and powerful Windows XP features are either ignored or given short shrift in the official Microsoft documentation. Whether it's the Windows XP startup options, group policies, or the Registry (to name just three that I discuss in this book), Microsoft prefers that curious users figure these things out for themselves (with, of course, the help of their favorite computer book authors).

The subject of this chapter is a prime example. The idea of the file type can be described, without hyperbole, as the very foundation of the Windows XP file system. Not only does Microsoft offer scant documentation and tools for working with file types, but they also seem to have gone out of their way to hide the whole file type concept. As usual, the reason is to block out this aspect of Windows XP's innards from the sensitive eyes of the novice user. Ironically, however, this just creates a whole new set of problems for beginners and more hassles for experienced users.

This chapter brings file types out into the open. You'll learn the basics of file types and then see a number of powerful techniques for using file types to take charge of the Windows XP file system.

Understanding File Types

To get the most out of this chapter, you need to understand some background about what a file type is and how Windows XP determines and works with file types. The next couple of sections tell you everything you need to know to get you through the rest of the chapter.

File Types and File Extensions

One of the fictions that Microsoft has tried to foist on the computer-using public is that we live in a "document-centric" world. That is, that people care only about the documents they create and not about the applications they use to create those documents. This is pure hokum. The reality is that applications are still too difficult to use and the capability to share documents between applications is still too problematic. In other words, you can’t create documents unless you learn the ins and outs of an application, and you can’t share documents with others unless you use compatible applications.

Unfortunately, we’re stuck with Microsoft’s worship of the document and all the problems that this worship creates. A good example is the hiding of file extensions. As you learned in Chapter 2, "Exploring Expert File and Folder Techniques," Windows XP turns off file extensions by default. Here are just a few of the problems this allegedly document-centric decision creates:

Document confusion

If you have a folder with multiple documents that use the same primary name, it’s often difficult to tell which file is which. For example, Figure 3.1 shows a folder with 15 different files named Project. Windows XP unrealistically expects users to tell files apart just by examining their icons.

The inability to rename extensions

If you have a file named index.txt and you want to rename it to index.html, you can’t do it with file extensions turned off. If you try, you just end up with a file named index.html.txt.

The inability to save a document

Similarly, with file extensions turned off, Windows XP forces under an extension of your choice you to save a file using the default extension associated with an application. For example, if you’re working in Notepad, every file you save must have a .txt extension.


Figure 3.1

Figure 3.1 With file extensions turned off, it’s often difficult to tell one file from another.

You can overcome all these problems by turning on file extensions. Why does the lack of file extensions cause such a fuss? Because file extensions solely and completely determine the file type of a document. In other words, if Windows XP sees that a file has a .txt extension, it knows the file uses the Text Document file type. Similarly, a file with the extension .bmp uses the Bitmap Image file type.

The file type, in turn, determines the application that’s associated with the extension. If a file has a .txt extension, Windows XP associates that extension with Notepad, so the file will always open in Notepad. Nothing else inherent in the file determines the file type so, at least from the point of view of the user, the entire Windows XP file system rests on the shoulders of the humble file extension.

This method of determining file types is, no doubt, a poor design decision. (For example, there is some danger that a novice user could render a file useless by imprudently renaming its extension.) However, it also leads to some powerful methods for manipulating and controlling the Windows XP file system, as you’ll see in this chapter.

File Types and the Registry

As you might expect, everything Windows XP knows about file types is defined in the Registry. (See Chapter 8, "Getting to Know the Windows XP Registry," for details on understanding and using the Registry.) You use the Registry to work with file types throughout this chapter, so let’s see how things work. Open the Registry Editor and examine the HKEY_CLASSES_ROOT key. Notice that it’s divided into two sections:

To see what this all means, take a look at Figure 3.2. Here, I’ve highlighted the .txt key, which has txtfile as its Default value.

Figure 3.2

Figure 3.2 The first part of the HKEY_CLASSES_ROOT key contains subkeys for all the registered file extensions.

That Default value is a pointer to the extension’s associated file type subkey in the second half of HKEY_CLASSES_ROOT. Figure 3.3shows the txtfile subkey associated with the .txt extension. Here are some notes about this file type subkey:

Figure 3.3

Figure 3.3 The second part of HKEY_CLASSES_ROOT contains the file type data associated with each extension.

The File Types Tab: A Front-End for HKEY_CLASSES_ROOT

For much of the work you do in this chapter, you won’t have to deal with the Registry’s HKEY_CLASSES_ROOT key directly. Instead, Windows XP offers a dialog box tab that acts as a front-end for this key. Follow these steps to display this tab:

  1. In Windows Explorer, select Tools, Folder Options to display the Folder Options dialog box.

  2. Select the File Types tab.

Figure 3.4 shows the File Types tab. The Registered File Types list shows all the file types known to Windows XP, as well as their extensions. When you select a file type, the Opens With line in the Details area shows you the icon and name of the program associated with the file type.

Working with Existing File Types

In this section, you’ll learn how to work with Windows XP’s existing file types. I’ll show you how to change the file type description, modify the file type’s actions, associate an extension with another file type, and disassociate a file type and an extension.

Figure 3.4

Figure 3.4 The File Types tab offers a front-end for working with Windows XP’s registered file types.

Editing a File Type

To make changes to an existing file type, follow these steps:

  1. Open the Folder Options dialog box and display the File Types tab, as described earlier.

  2. Use the Registered File Types list to select the file type you want to work with.

  3. Click Advanced. The Edit File Type dialog box appears. Figure 3.5 shows the Edit File Type dialog box for the Text Document type.

  4. The text box at the top holds the description of the file type, which you can edit. This description appears in the Registered File Types list and in the New menu (right-click a folder and then click New).

  5. You can also work with the following controls:

  6. Change Icon

    Click this button to display the Change Icon dialog box. Use this dialog box to select a new icon for the file type.

    Actions

    This list shows the actions defined for the file type. I discuss file type actions in more detail in the next section.

    Confirm Open After Download

    When this check box is activated and you attempt to download a file from the World Wide Web, Internet Explorer displays the File Download dialog box that asks whether you want to save or open the downloaded file (see Figure 3.6). Otherwise, Internet Explorer just opens the file using its associated application. Here are two points to bear in mind:

    • Despite the name of this check box, Internet Explorer displays the File Download dialog box before you download the file.

    • For many file types, the File Download dialog box includes a check box named Always Ask Before Opening This Type of File. Deactivating this check box is the same thing as deactivating the Confirm Open After Download check box.

    Always Show Extension

    If you activate this check box, Windows XP shows this file type's extension even if you hide extensions globally.

    Browse in Same Window

    When this check box is activated, the file type opens within Internet Explorer instead of its associated application. This applies only to Microsoft Office file types that are capable of being displayed within Internet Explorer.


  7. Click OK to return to the File Types tab.

  8. Click Close.

Figure 3.5

Figure 3.5 Use the Edit File Type dialog box to make changes to an existing file type.

Figure 3.6

Figure 3.6 If the Confirm Open After Download check box is activated, Internet Explorer displays this dialog box.

Working with File Type Actions

In the Edit File Type dialog box, the Actions list displays the defined actions for the file type. You usually see two types of actions:

The buttons beside the Actions list enable you to work with the file type’s actions:

New

Click this button to create a new action for the file type. See "Creating a New File Type Action," later in this chapter.

Edit

Click this button to make changes to the selected action. See "Editing a File Type Action," later in this chapter.

Remove

Click this button to delete the selected action.

Set Default

Click this button to make the selected action the default for this file type.


Associating an Extension with a Different Application

There are many reasons you might want to override Windows XP’s default associations and use a different program to open an extension. For example, you might prefer to open text files in WordPad instead of Notepad. Similarly, you might want to open HTML files in Notepad or some other text editor rather than Internet Explorer.

In these cases, you need to associate the extension with the application you want to use instead of the Windows default association. Windows XP gives you two ways to go about this:

The Open With dialog box

With this method, right-click any file that uses the extension and then click Open With. (If you’ve used the Open With dialog box on this extension before, click the Choose Program command from the menu that appears.) In the Open With dialog box, select the program you want to use, activate the Always Use This Program to Open These Files check box, and click OK.

The File Types tab

With this method, you use the File Types tab to edit the Open action of the file type. See the next section to learn how to edit a file type action.


Editing a File Type Action

Follow these steps to make changes to a file type action:

  1. In the File Types tab, select the file type you want to work with.

  2. Click the Advanced button. The Edit File Type dialog box appears.

  3. In the Actions list, select the action you want to change, and then click Edit. The Editing Action for Type: Type dialog box appears (where Type is the file type you're working with).

  4. (Optional) Use the Action text box to change the name of the action.

  5. In the Application Used to Perform Action text box, type the full pathname of the application you want to use for the action. Here are some notes to bear in mind:

Creating a New File Type Action

Instead of replacing an action’s underlying application with a different application, you might prefer to create new actions. In our HTML file example, you could keep the default Open action as it is and create a new action—called, for example, Open for Editing—that uses Notepad (or whatever) to open an HTML file. When you highlight an HTML file and pull down the File menu, or right-click an HTML file, the menus that appear will show both commands: Open (for Internet Explorer) and Open for Editing (for Notepad).

To create a new action for an existing file type, follow these steps:

  1. In the File Types tab, select the file type you want to work with.

  2. Click the Advanced button. The Edit File Type dialog box appears.

  3. Click New to display the New Action dialog box.

  4. Use the Action text box to enter a name for the action.

  5. Use the Application Used to Perform Action text box to enter the full pathname of the application you want to use for the new action. (Follow the guidelines that I outlined in the previous section.)

  6. Click OK.

  7. If you want the new action to be the default, select it and click Set Default.

  8. Click OK to return to the File Types tab.

  9. Click Close.

Example: Opening the Command Prompt in the Current Folder

When you’re working in Windows Explorer, you might find occasionally that you need to do some work at the command prompt. For example, the current folder might contain multiple files that need to be renamed—a task that’s most easily done within a command-line session. Selecting Start, All Programs, Accessories, Command Prompt starts the session in the %USERPROFILE% folder, so you have to use one or more CD commands to get to the folder you want to work in.

An easier way would be to create a new action for the Folder file type that launches the command prompt and automatically displays the current Windows Explorer folder. To do this, follow these steps:

  1. Select Folder in the File Types tab.

  2. Click Advanced to display the Edit File Type dialog box.

  3. Click New to display the New Action dialog box.

  4. Type Open &With Command Prompt in the Action text box (note that the letter W is the accelerator key).

  5. cmd.exe /k cd "%L"
  6. Figure 3.7 shows a completed dialog box. Click OK when you’re done. Windows XP adds your new action to the Folder type’s Actions list.

Figure 3.7

Figure 3.7 Use the New Action dialog box to define a new action for the file type.

In Figure 3.8, I right-clicked a folder. Notice how the new action appears in the shortcut menu. The command prompt window below is what appears if you click the Open With Command Prompt command.

Figure 3.8

Figure 3.8 The new action appears in the file type’s shortcut menu.

Disassociating an Application and an Extension

One of the most annoying things a newly installed program can do is change your existing file type associations. Some programs are courteous enough to ask you whether they can change some associations. However, many other programs make the changes without permission. In these cases, you often want to undo the damage by disassociating the new application from the affected extensions. You have two ways to proceed:

Creating a New File Type

Windows XP comes with a long list of registered file types, but it can’t account for every extension you’ll face in your computing career. For rare extensions, it’s best just to use the Open With dialog box. However, if you have an unregistered extension that you encounter frequently, you should register that extension by creating a new file type for it. The next two sections provide a couple of methods for doing this.

Using Open With to Create a Basic File Type

Our old friend the Open With dialog box provides a quick-and-dirty method for creating a simple file type for an unregistered extension:

  1. In Windows Explorer, select the file you want to work with.

  2. Select File, Open. (For unregistered file types, Windows XP doesn’t display the Open With command.) Windows XP displays a dialog box telling you that it cannot open the file, as shown in Figure 3.9.

  3. Figure 3.9

    Figure 3.9 Windows XP displays this dialog box when you attempt to open an unregistered file type.

  4. Activate the Select the Program from a List option and then click OK. The Open With dialog box appears.

  5. In the Programs list, select the application you want to use to open the file or click Browse to choose the program from a dialog box.

  6. Use the Type a Description That You Want to Use for This Kind of File text box to enter a description for the new file type.

  7. Make sure that the Always Use the Selected Program to Open This Kind of File check box is activated.

  8. Click OK.

This method creates a new file type with the following properties:

Using the File Types Tab to Create a More Advanced File Type

If you want more control over your new file type, use the File Types tab instead of the Open With dialog box. This method enables you to select a different icon, set up multiple actions, and more. Here are the steps to follow:

  1. Open the Folder Options dialog box and display the File Types tab.

  2. Click New. Windows XP displays the Create New Extension dialog box shown in Figure 3.10.

  3. Figure 3.10 Use the Create New Extension dialog box to define your new file type.

  4. Type the File Extension for the new file type.

  5. Click OK to return to the File Types tab.

  6. Select the new extension in the Registered File Types list.

  7. Click Advanced to display the Edit File Type dialog box.

  8. Change the file type description and icon, if desired. Follow the steps I outlined in the "Creating a New File Type Action" section to create an Open action for the new file type, as well as any other actions you require (such as Edit or Print).

  9. Click OK.

  10. Click Close.

Associating Two or More Extensions with a Single File Type

The problem with creating a new file type is that you often have to reinvent the wheel. For example, let’s say you want to set up a new file type that uses the .1st extension. These are usually text files (such as readme.1st) that provide pre-installation instructions, so you probably want to associate them with Notepad. However, this means repeating some or all of the existing Text Document file types. To avoid this, it’s possible to tell Windows XP to associate a second extension with an existing file type. Here are the steps to follow:

  1. Open the Folder Options dialog box and display the File Types tab.

  2. Click New. Windows XP displays the Create New Extension dialog box.

  3. Type the File Extension for the new file type.

  4. Click Advanced. The dialog box expands as shown in Figure 3.11.

  5. Figure 3.11

    Figure 3.11 The expanded version of the Create New Extension dialog box.

  6. Use the Associated File Type list to select the file type for the new extension (such as Text Document).

  7. Click OK to return to the File Types tab.

Customizing the New Menu

One of Windows XP’s handiest features is the New menu, which enables you to create a new file without working within an application. In Windows Explorer, select File, New, or right-click inside the Contents pane and select New. In the submenu that appears, you’ll see items that create new documents of various file types, including a folder, shortcut, bitmap image, WordPad document, text document, compressed folder, and possibly many others, depending on your system configuration and the applications you have installed.

What mechanism determines whether a file type appears on the New menu? The Registry, of course. To see how this works, start the Registry Editor and open the HKEY_CLASSES_ROOT key. As you’ve seen, most of the extension subkeys have only a Default setting that’s either blank (if the extension isn’t associated with a registered file type) or a string file that points to the extension’s associated file type.

However, lots of these extension keys also have subkeys and a few of them have a subkey named ShellNew, in particular. For example, open the .bmp key and you see that it has a subkey named ShellNew. This subkey is what determines whether a file type appears on the New menu. Specifically, if the extension is registered with Windows XP and it has a ShellNew subkey, the New menu sprouts a command for the associated file type.

The ShellNew subkey always contains a setting that determines how Windows XP creates the new file. Four settings are possible:

NullFile

This setting, the value of which is always set to a null string (""), tells Windows XP to create an empty file of the associated type. Of the file types that appear on the default New menu, three use the NullFile setting: Text Document (.txt), Bitmap Image (.bmp), and WordPad Document (.doc).

FileName

This setting tells Windows XP to create the new file by making a copy of another file. Windows XP has special hidden folders to hold these template files. These folders are user-specific, so you'll find them in %USERPROFILE%\Templates. On the default New menu, only the Wave Sound (.wav) file type uses the FileName setting, and its value is sndrec.wav. To see this value, you need to open the following key:

HKEY_CLASSES_ROOT\.wav\ShellNew

Command

This setting tells Windows XP to create the new file by executing a specific command. This command usually invokes an executable file with a few parameters. Two of the New menu's commands use this setting:

  • Shortcut—The .lnk\ShellNew key contains the following value for the Command setting:

  • rundll32.exe appwiz.cpl,NewLinkHere %1

  • Briefcase—In the .bfc\ShellNew key, you'll see the following value for the Command setting:

    %SystemRoot%\system32\rundll32.exe %SystemRoot%\system32\syncui.dll,Briefcase_Create %2!d! %1

Data

This setting contains a binary value, and when Windows XP creates the new file, it copies this binary value into the file. The New menu's Compressed (Zipped) Folder command uses this setting, which you can find here:

.zip\CompressedFolder\ShellNew

Adding File Types to the New Menu

To make the New menu even more convenient, you can add new file types for documents you work with regularly. For any file type that’s registered with Windows XP, you follow a simple three-step process:

  1. Add a ShellNew subkey to the appropriate extension key in HKEY_CLASSES_ROOT.

  2. Add one of the four settings discussed in the preceding section (NullFile, FileName, Command, or Data).

  3. Type a value for the setting.

In most cases, the easiest way to go is to use NullFile to create an empty file. However, the FileName setting can be quite powerful because you can set up a template file containing text and other data.

Deleting File Types from the New Menu

Many Windows XP applications (such as Microsoft Office) like to add their file types to the New menu. If you find that your New menu is getting overcrowded, you can delete some commands to keep things manageable. To do this, you need to find the appropriate extension in the Registry and delete its ShellNew subkey.

Customizing Windows XP’s Open With List

You’ve used the Open With dialog box a couple of times so far in this chapter. This is a truly useful dialog box, but you can make it even more useful by customizing it. The rest of this chapter takes you through various Open With customizations.

Opening a Document with an Unassociated Application

From what you’ve learned in this chapter, you can see the process that Windows XP goes through when you double-click a document:

  1. Look up the document’s extension in HKEY_CLASSES_ROOT.

  2. Examine the Default value to get the name of the file type subkey.

  3. Look up the file type subkey in HKEY_CLASSES_ROOT.

  4. Get the Default value in the shell\open\command subkey to get the command line for the associated application.

  5. Run the application and open the document.

What do you do if you want to bypass this process and have Windows XP open a document in an unassociated application? (That is, an application other than the one with which the document is associated.) For example, what if you want to open a text file in WordPad?

One possibility would be to launch the unassociated application and open the document from there. To do so, you’d run the File, Open command (or whatever) and, in the Open dialog box, select All Files (*.*) in the Files of Type list.

That will work, but it defeats the convenience of being able to launch a file directly from Windows Explorer. Here's how to work around this:

  1. In Windows Explorer, select the document you want to work with.

  2. Select File, Open With. (Alternatively, right-click the document, and then click Open With in the shortcut menu.)

  3. The next step depends on the file you're working with:

  4. In the Programs list, select the unassociated application in which you want to open the document. (If the application you want to use isn't listed, click Browse and then select the program's executable file from the dialog box that appears.)

  5. To prevent Windows XP from changing the file type to the unassociated application, make sure that the Always Use the Selected Program to Open This Kind of File check box is deactivated.

  6. Click OK to open the document in the selected application.

One of the small but useful interface improvements in Windows XP is that the system remembers the unassociated applications that you choose in the Open With dialog box. When you next select the Open With command for the file type, Windows XP displays a menu that includes both the associated program and the unassociated program you chose earlier.

How the Open With Feature Works

Before you learn about the more advanced Open With customizations, you need to know how Windows XP compiles the list of applications that appear on the Open With list:

Removing an Application from a File Type’s Open With Menu

When you use the Open With dialog box to choose an alternative application to open a particular file type, that application appears on the file type’s Open With menu (that is, the menu that appears when you select the File, Open With command). To remove the application from this menu, open the following Registry key (where ext is the file type’s extension):

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\
FileExts\.ext\OpenWithList

Delete the setting for the application you want removed from the menu. Also, edit the MRUList setting to remove the letter of the application you just deleted. For example, if the application setting you deleted was named b, delete the letter b from the MRUList setting.

Removing a Program from the Open With List

Rather than customizing only a single file type’s Open With menu, you might need to customize the Open With dialog box for all file types. To prevent a program from appearing in the Open With list, open the Registry Editor and navigate to the following key:

HKEY_CLASSES_ROOT/Applications

Here you’ll find a number of subkeys, each of which represents an application installed on your system. The names of these subkeys are the names of each application’s executable file (such as notepad.exe for Notepad). To prevent Windows XP from displaying an application in the Open With list, highlight the application’s subkey, and create a new string value named NoOpenWith. (You don’t have to supply a value for this setting.) To restore the application to the Open With list, delete the NoOpenWith setting.

Adding a Program to the Open With List

You can also add an application to the Open With dialog box for all file types. Again, you head for the following Registry key:

HKEY_CLASSES_ROOT/Applications

Display the subkey named after the application’s executable file. (If the subkey doesn’t exist, create it.) Now add the \shell\open\command subkey and set the Default value to the pathname of the application’s executable file.

Disabling the Open With Check Box

The Open With dialog box enables you to change the application associated with a file type’s Open action by activating the Always Use the Selected Program to Open This Kind of File check box. If you share your computer with other people, you might not want them changing this association, either accidentally or purposefully. In that case, you can disable the check box by adjusting the following Registry key:

HKEY_CLASSES_ROOT\Unknown\shell\openas\command

The Default value of this key is the following

%SystemRoot%\system32\rundll32.exe %SystemRoot%\system32\shell32.dll,
OpenAs_RunDLL %1

To disable the check box in the Open With dialog box, append %2 to the end of the Default value:

%SystemRoot%\system32\rundll32.exe %SystemRoot%\system32\shell32.dll,
OpenAs_RunDLL %1 %2

From Here

Here are some other places in the book where you’ll find related information:

800 East 96th Street, Indianapolis, Indiana 46240