Microsoft Windows Registry Guide, Second Edition

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:

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:

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.

Table A-1 Bits in EditFlags

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:

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.

Категории