Program Class Keys
Program classes define a program and the behaviors associated with it. Program classes are in HKCR\progid, where progid is a program identifier. For example, HKCR\txtfile is a program class. Windows associates file extension keys with program classes through the file extension keys' default values. The default value of the program class contains the class's friendly name. The proper format of a program ID is application.component.version. For example, Word.Document.6 is a proper program ID. This format isn't always used, though, not even by Windows.
Program classes contain the following values and subkeys:
This empty REG_SZ value indicates that Windows Explorer should always show the file extension, even if the user has hidden it.
The default value of this subkey contains the program ID of the most current version.
The default value of this subkey is the default icon that Windows displays for files associated with this program class. This value can be either a REG_SZ or a REG_EXPAND_SZ string, but it must use the format file,index, where file is the path and name of the file containing the icon, and index is the index of the icon in the file. Optionally, if you know the exact resource ID, you can use the format file,-resource. See the “DefaultIcon” section that follows for more information.
This is a REG_DWORD value that controls how Windows handles file classes linked to this program class. You can also use the EditFlags value to control users' ability to modify certain aspects of these file classes. See the “EditFlags” section that follows for more information.
This REG_SZ value is the friendly name for the program class. You see this value in Windows Explorer. In Windows, this value supercedes the program class's default value, which earlier versions of Windows still use and Windows maintains for backward compatibility. Still, the default value of the program class and this value should remain the same for consistency. Windows commonly specifies a resource instead of a string in this value. The format is @file,index or @file,-resource.
This REG_SZ value contains a brief message that Windows displays for this program class when users position the mouse pointer over a file or folder linked to it. This value can be a string or a resource as described for the FriendlyTypeName value.
This empty REG_SZ values indicates that the file is a shortcut. Windows Explorer displays the shortcut overlay on top of the file's icon.
This empty REG_SZ value indicates that Windows Explorer should never show the file extension, even if the user has configured Windows Explorer to show file extensions for known types.
This subkey contains commands (called verbs) defined for the program class. For example, the txtfile program class defines the commands for opening and printing text files. See the “Shell” section, later in this appendix, for more information. This subkey is the heart of most customizations you'll do in HKCR.
Special Program Classes
The program classes Directory, Drive, and Folder are specialized program classes that are useful to customize. The organization of these program classes is just like any other. They contain Shell subkeys that you can customize to add, change, and remove the commands you see on their shortcut menus. The trick is knowing which program classes apply to which types of objects:
This program class applies to any normal folder that you can view in Windows Explorer.
This program class applies only to drives that you see in My Computer.
This program class applies to all system folders, drives, and other folders that you can view in Windows Explorer.
The program class Folder is the most inclusive. It includes all folders and all special system folders, such as Control Panel, My Computer, and so on. As such, this is typically the program class that you want to customize unless you need to restrict your customization to specific drives or non-system folders.
DefaultIcon
Windows provides default icons for every type of object you see in Windows Explorer. That includes files, drives, and so on. You can customize these icons as described in Chapter 4, “Hacking the Registry.” Each file class's DefaultIcon value contains the path and name of the file containing the icon. You can assign an icon file, which has the .ico extension, to this value, or you can assign an icon from program files using the formats file,index or file,-resource. Index is an incremental index number of a resource, and resource is a specific resource ID. Doing this requires that you know either the relative location of an icon in a file or the icon's exact resource ID. To find this value, you can use a third-party resource editor. Many third-party resource editors are shareware tools you can download from your favorite shareware Web site.
EditFlags
The REG_DWORD value EditFlags gives you some control of a program class's behavior. You can also use it to limit the ways in which users can change a program class. Each bit in this value represents a different setting, and Table A-1 describes the bit mask of each. See Chapter 1, “Learning the Basics,” to refresh your memory on how to use bit masks.
Bit mask | Description |
0x00000001 | Excludes the file class. |
0x00000002 | Shows file classes, such as folders, that aren't associated with a file extension. |
0x00000004 | Denotes that the file class has a file extension. |
0x00000008 | Prevents users from editing the registry entries associated with this file class. They can't add new entries or change existing entries. |
0x00000010 | Prevents users from deleting the registry entries associated with this file class. |
0x00000020 | Prevents users from adding new verbs to the file class. |
0x00000040 | Prevents users from changing verbs. |
0x00000080 | Prevents users from deleting verbs. |
0x00000100 | Prevents users from changing the description of the file class. |
0x00000200 | Prevents users from changing the icon assigned to the file class. |
0x00000400 | Prevents users from changing the default verb. |
0x00000800 | Prevents users from changing the commands associated with verbs. |
0x00001000 | Prevents users from modifying or deleting verbs. |
0x00002000 | Prevents users from changing or deleting DDE-related values. |
0x00008000 | Prevents users from changing the content type associate with this file class. |
0x00010000 | Allows users to safely use the file class's open verb for downloaded files. |
0x00020000 | Disables the Never Ask Me check box. |
0x00040000 | Denotes that the file class's file name extension is always shown, even if the user hides known file extensions in the Folder Options dialog box. |
0x00100000 | Denotes that members of this file class are not added to the Recent Documents folder. |
Shell
File classes contain verbs, which are commands that Windows executes to complete certain actions. Verbs are related to the shortcut menus that you see when you right-click a file. Each item on the shortcut menu is a verb. A program class's verbs are in HKCR\progid\Shell, which contains one subkey for each verb. For example, HKCR\txtfile\Shell contains the subkeys open and print, which are the Open and Print verbs. The default value of the Shell key indicates the name of the default verb. For example, if the default value of Shell is edit, the subkey edit is the default verb. If the default value of Shell is empty, Windows uses the verb open. If that verb is missing, it uses the first verb as the default. Figure A-2 shows an example that relates the Shell key to shortcut menus.
Figure A-2 This figure shows the relationship of a program class's verbs to the shortcut menu.
Canonical verbs are built into the operating system. Examples of canonical verbs are Open, Edit, and Print. One thing that makes canonical verbs special is that Windows automatically translates them to different languages as necessary. The following list shows typical canonical verbs, some of which are special verbs that users don't see on menus:
This verb is usually the same as Open, but it enables the user to edit the file's contents.
This verb opens the selected folder in Windows Explorer.
This verb opens Search Assistant with the selected folder as the default search location.
This verb is typically the default verb, which opens a file in the associated application.
This verb opens the Open With dialog box.
This verb indicates that the contents of the file will be opened and played, rather than just opening the file and waiting for the user to play it.
This verb enables users to preview files without opening or editing them. An example is previewing images, rather than opening to edit them.
This verb causes the application to print the file's contents and exit. Applications should display as little user interface as possible.
This verb is a special verb that supports performing drag-and-drop operations to printers. Users don't see this verb on shortcut menus.
This verb opens the Name Properties dialog box.
This is a special verb that enables users to open a file or run an application in the context of a different user. Users can see this verb on shortcut menus by holding down the SHIFT key while right-clicking the file.
You can add supplemental verbs to any program class. For example, you can add the verb Edit in WordPad to the txtfile program class to have the option of editing text files in WordPad without changing the default verbs. To add verbs to a program class, create a new subkey for it in the Shell key. The new subkey is HKCR\ progid \Shell\verb. Then set the default value of the verb to the text you want to see on the shortcut menu. You can make any character in the description a hotkey by prefixing it with an ampersand (&). For example, Open in &WordPad makes the letter W a hotkey for that the verb. Add the subkey command to the verb, and set its default value to the command you want to execute when you choose that verb. Figure A-3 shows an example.
Figure A-3 Add supplemental verbs to a program class by creating new subkeys in Shell.
The default value of the command needs a bit more explanation. First, if the path and name of the program file contain spaces, you should enclose the command in quotation marks. Second, you use %1 as a placeholder for the file name that you right-clicked. For example, assume the command is Notepad “%1”. If you right-click C:\Sample\Text.txt, the command is Notepad “C:\Sample\Text.txt”. Note that you should always enclose %1 in quotation marks so that the command works with long file names.
You see extended verbs only when you press the SHIFT key while right-clicking a file. Creating extended verbs is a handy way to remove clutter from shortcut menus. For example, you can add extended verbs that you don't use often to shortcut menus, hiding them behind the SHIFT key. To make a verb an extended verb, add the empty REG_SZ value extended to the verb's subkey, Shell\ verb.