Logo
programming4us
programming4us
programming4us
programming4us
Home
programming4us
XP
programming4us
Windows Vista
programming4us
Windows 7
programming4us
Windows Azure
programming4us
Windows Server
programming4us
Windows Phone
 
Windows Vista

File Type Associations (part 1) - Anatomy of a File Type

- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019
10/18/2011 5:36:23 PM
File type associations are the links between your documents and the applications that use them. The most apparent use of this feature is that, for example, Windows knows to open Notepad when you double-click a text document on the desktop or show you an online advertisement for anatomical enhancement if you click the link in a spam email message.

One might assume that the aforementioned text file somehow knows it's a Notepad document, but that isn't the case. Instead, Windows determines how to handle a file based solely on the filename extension. The extension is the group of 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. Likewise, the extension of Resume.docx is .docx, which means it's a word processor document in the Microsoft Word 2007 file format.

There are a number of filename extension databases on the Web, which is useful if you encounter a file you can't open and don't recognize. Some of the better resources include http://wikipedia.org/wiki/list_of_file_formats and http://filext.com. Alternatively, you can double-click the unknown file and when Windows asks you what you want to do (Figure 1), select Use the Web service to find the correct program, and click OK. Just don't be surprised if you don't get a satisfying response.


Figure 1. If you see this window, the selected file's filename extension isn't currently registered on your PC


It may seem silly that so much of Windows' ability to open files rests on something as easy to break as the filename, but the design does have its advantages. For instance, it's fairly easy to change the program used to open all your digital photos without having to modify all your .jpg files to do it.

The biggest flaw in the system is that Windows hides filename extensions by default, which is why Windows Explorer shows only Readme instead of Readme.txt. Fortunately, this is easy enough to change; just open Folder Options in Control Panel (or click Organize → Folder and Search Options in Windows Explorer). In the Folder Options window, choose the View tab, turn off the Hide extensions for known file types option, and click OK.

If you have Windows show filename extensions, it's easier to determine what kind of files you're dealing with. Instead of merely a file named recipe, you might see recipe.tif if it's a scan of a recipe, recipe.pdf if it's an Acrobat file with a recipe inside, or recipe.exe if it's a Trojan horse you just received via email. Sure, you'll have to open the file to see whether you're making cookies or explosives, but at least you can anticipate which application will appear, and will know whether or not you'll have to convert it to a different format before posting it on your Chocolate Chip Anarchist blog.

Having extensions visible also means you can change Windows' perception of the type of a file by merely renaming its 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.)

Now, Microsoft started hiding filename extensions back in Windows 95 (in a vain attempt to make Windows easier to use), but it's never been handled well. For instance, if you have more than one file, side-by-side, with the same name, having your extensions hidden just makes things more confusing. Rather than recipe.jpg, recipe.wpd, and recipe.txt, you'll just see recipe, recipe, and recipe, with only a miniscule icon to distinguish them.

And since only registered filename extensions are hidden, recipe.pdf would normally appear as recipe.pdf until you install Adobe Acrobat Reader. Once Acrobat registers the .pdf file type, the .pdf extensions vanish, and the file will be shown merely as recipe... unless you elect to make file extensions visible as described above. But what does it mean to register a file type?

1. Anatomy of a File Type

A registered file type is constructed out of a handful of keys and values in the Registry that Windows reads in real time to handle your documents appropriately. Register a new file type, and Windows will know what to do with files of that type right away.

Usually it's an installer or an application that registers new file types, but anyone (or any program, for that matter) can add new ones or modify existing file type associations. Customizing your PC's file types is one of the most effective ways to save time and reduce annoyances in Windows, but Vista doesn't make it easy, so you've got to know what makes them tick first.

It starts with a single key in HKEY_CLASSES_ROOT, named for a filename extension (including the dot). The (Default) value in that key contains the name of another key that has all the file type's meat in it. For instance, open up the Registry Editor and peer into these keys:

HKEY_CLASSES_ROOT\.log
HKEY_CLASSES_ROOT\.scp
HKEY_CLASSES_ROOT\.txt

Each one has a (Default) value that contains the word txtfile. Thus, each filename extension points to the txtfile file type, which is located in HKEY_CLASSES_ROOT\txtfile. And it's the txtfile key that has all the good stuff. See the "Special File Type Keys" sidebar for some catch-all file types.

Special File Type Keys

There are a few special file type keys in the Registry, each of which work like standard file types, despite having much greater scope. They are:


HKEY_CLASSES_ROOT\*

The asterisk (*) Registry key, conveniently placed at the top of the HKEY_CLASSES_ROOT tree in the Registry Editor, defines actions and extensions for all files. If there's a context menu item you'd like to eliminate, odds are it's in the Shell or ShellEx subkeys of the * key.

By adding a new action key to HKEY_CLASSES_ROOT\*\Shell, you can add a context menu item for all the files on your PC. For instance, you could add a key named OpenInNotepad, type Open in Notepad into the key's (Default) value, and then add a command key that points to notepad.exe, as described later in this section. When you're done, right-click any file and select Open in Notepad to view the file in a new Notepad window.


HKEY_CLASSES_ROOT\Unknown

This key is used to define the behavior of all files with unregistered file extensions. By default, there's only one file type here, openas, which is responsible for the dialog window in Figure 1. You can, of course, add new actions or even change the default action here. For example, you may work with a bunch of different types of documents Windows doesn't recognize, and wish to open them all in your favorite text editor without having to register them all first.


The system Windows uses to keep track of its file types has been around for years and has survived a bunch of different Windows versions. As a result, you'll see a lot of inconsistencies. Sometimes, for instance, the meat of a file type is actually in the extension key (e.g., HKEY_CLASSES_ROOT\.scp) rather than the file type key. Because Windows still allows this, some developers still do it this way, and in turn, you'll have to deal with it. Although most file types do follow the structure laid out on these pages, don't be surprised if you see something that doesn't belong and still works.


A typical file type key (e.g., HKEY_CLASSES_ROOT\txtfile) has a few values and subkeys, most of which appear in Figure 2.

Figure 2. A file type key has values and subkeys that determine how Windows treats associated files


First, the (Default) value contains the name of the type, the text that appears in Windows Explorer's Type column.

If a value named AlwaysShowExt is present in this key, the extension for this file type will be displayed in Explorer, even if you've elected to hide your filename extensions (a setting explained 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 instructs Explorer to always hide the extensions for these files, regardless of your preferences.

You'll also see some other values such as EditFlags, FriendlyTypeName, and InfoTip that are fairly inconsequential, but it's the stuff in the following three subkeys that's responsible for most of the magic:


DefaultIcon

The (Default) value in this key contains the full path and filename of the file containing the icon used for all files of this type.


Shell

Each subkey of Shell corresponds to an item (called an action) in the file's context menu.

ShellEx

The ShellEx branch lists Windows Explorer extensions, add-on programs designed to interact with Explorer and add features.

Once you know where all the essential keys are, you can use Registry Editor or one of the other tools mentioned in the upcoming sections to do just about anything you want with Vista's file types system. When you have everything the way you want it, don't forget to take some steps to protect your customized file types from overzealous application installers.

Other -----------------
- Registry Tasks and Tools (part 5) - Back Up the Registry
- Registry Tasks and Tools (part 4) - Export and Import Data with Registry Patches & Prevent Changes to a Registry Key
- Registry Tasks and Tools (part 3) - Create an Interface for a Registry Setting
- Registry Tasks and Tools (part 2) - Find the Registry Key That Does...
- Registry Tasks and Tools (part 1) - Search the Registry & Search and Replace Registry Data
- The Registry (part 1) - The Registry Editor & The Structure of the Registry
- Custom Startups Using the Boot Configuration Data (part 2) - Using BCDEDIT to Customize the Startup Options
- Custom Startups Using the Boot Configuration Data (part 1) - Using Startup and Recovery to Modify the BCD & Using the System Configuration Utility to Modify the BCD
- Customizing and Troubleshooting the Windows Vista Startup : The Boot Process, from Power Up to Startup
- Using Control Panel and Group Policies : Implementing Group Policies with Windows Vista
 
 
Top 10
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
 
programming4us
Windows Vista
programming4us
Windows 7
programming4us
Windows Azure
programming4us
Windows Server