File Extension Keys
Files containing particular types of data usually have the same file extension. For example, Microsoft Office Word 2003 documents have the .doc file extension. Although three-character extensions are the norm, extensions can be longer. Files with the same extension are members of a file class. File classes define behaviors common to all files that share that file name extension. By customizing file associations, you can specify which application opens a file, add commands to the shortcut menu, or even specify a custom icon that Windows Explorer will use for that type of file.
File associations have two parts. The first is a file extension key, HKCR\.ext. When Windows needs information about a file type, it looks up this key. The default value of the file extension key contains the name of the program class associated with it, which is the second part. Program classes are in HKCR\progid, where progid is the program ID of the application. The default value of progid contains the friendly name of the application. For example, the file extension key HKCR\.txt has a default value of txtfile. If you look in HKCR\txtfile to find the program class associated with it, you'll find the description Text File. Figure A-1 illustrates this relationship with the .ani file extension.
Figure A-1 The default values of file extension keys associate these keys with program classes.
File extension keys can have a variety of subkeys and values. The following list describes the most common:
This subkey contains one or more keys bearing the names of the applications to appear in the Recommended Programs list in the Open With dialog box. See the “OpenWithList” section that follows for more information.
This REG_SZ value indicates the file's perceived type. Windows XP and Windows Server 2003 are the only versions of Windows that use this key. See the “PerceivedType” section that follows for more information.
This subkey defines a template from which Windows creates a new file when users choose this file type on the New menu. See the “ShellNew” section that follows for more information.
This REG_SZ value indicates the MIME type.
This subkey contains a list of alternate program classes associated with the file extension. Windows displays these programs in the Other Programs list in the Open With dialog box.
OpenWithList
Sometimes users want to open files with applications that aren't associated with the file class. For example, a user might want to open a document in WordPad instead of Microsoft Office Word 2003. In other cases, users might want to open files that have no file associations. The Open With dialog box allows both scenarios.
The applications you see in the Open With dialog box are registered in HKCR\Applications. This key contains one subkey for each application, and the subkey bears the name of the program's executable file. You can prevent Windows from displaying an application in the Open With dialog box by adding the REG_SZ value NoOpenWith to HKCR\Applications\program .exe.
PerceivedType
Perceived types are similar to file types, except perceived types refer to broad categories of file format types, rather than to specific types of files. Think of them as super types. Perceived types include images, text files, audio files, and compressed files. In Windows, you can associate a perceived type with each file type. For example, the file extensions .bmp, .png, .jpg, and .gif are perceived as image files. Windows defines several perceived file types. In the file extension key, you set the REG_SZ value PerceivedType to one of the following:
|
|
ShellNew
When users right-click in a folder and click New, they see a list of template files that they can create in the folder. You can extend the New menu with additional file templates. First make sure that HKCR contains a file extension key for the type of file you're creating. Then create the ShellNew subkey under the file extension key. For example, to define a template for files with the .inf extension, create the key HKCR\.inf\ShellNew. Then in ShellNew, create one of the following values:
Executes an application. This is a REG_SZ value command to execute. For example, you use a command to launch a wizard.
Creates a file containing specified data. This is a REG_BINARY value that contains the file's data. Windows ignores this value if either NullFile or File Name exists.
Creates a file that is a copy of a specified file. This is a REG_SZ value that contains the path and name of the file to copy. If the file is in the user profile's Templates folder, you can leave off the path.
Creates an empty file. This is a REG_SZ value that contains no data. If the value NullFile exists, Windows ignores Data and File Name.