Customizing File Associations

File associations control the following aspects of how Windows XP treats files:

  • Which icon Windows XP displays for a file

  • Which application launches when users double-click files

  • How Windows Explorer displays particular types of files

  • Which commands appear on files' shortcut menus

  • Other features, such as InfoTips

Appendix A, "File Associations," describes file associations in detail. In that chapter, you also learn how to customize file associations in ways that only programmers know—until now. Because Appendix A gives the full treatment to file associations and the root key that contains them, HKCR, I'm not going to duplicate that material here. I thought you'd have more fun with some specific file association customizations that I like, such as adding Tweak UI to the My Computer icon's shortcut menu or opening an MS-DOS command prompt at a particular folder.

start sidebar
File Associations in the Registry

I said that Appendix A, "File Associations," is the place to go to learn about file associations in HKCR, but a quick brain dump will help you use the hacks you see in this chapter. Take a look at Figure 4-4, which shows how Windows XP chooses what to display on a file's shortcut menu.

click to expand
Figure 4-4: A file extension key's default value indicates the program class with which it's associated. The program class's shell subkey contains commands you see on the shortcut menu.

In the figure on the previous page, you see the keys that Windows XP consults when you right-click a text file and then click Open. First the operating system looks up the file extension in HKCR. The default value, shown in Figure 4-4, indicates that the program class associated with the .txt file extension is txtfile. So the operating system looks in HKCR\txtfile for the subkey shell to find the commands it adds to the shortcut menu. For example, as shown in Figure 4-4, Windows XP adds Open to the shortcut menu, and when users choose Open, it runs the command in the command subkey.

The command in the command subkey is usually "program" options "%1 ". program is the path and file name of the program you want to run. If you're using a script and change the default value of command to REG_EXPAND_SZ, you can use environment variables like %SYSTEMROOT% in it. Otherwise, use an explicit path. You use the %1 as a placeholder for the target file. Windows XP will add the path and name of the target file to the end of the command, but you don't want to leave this up to chance. Also, always enclose %1 in quotes in case the target path and file name include spaces.

You often see this same shell subkey in class registrations, too. For example, the class registration for My Computer contains a command for managing the computer. The class registration for Recycle Bin contains commands to empty and explore its contents.

end sidebar

Running Programs from My Computer

I'm all for any customization that makes things easier. There are some programs that I use over and over again, and I want a nice, easy place from which to run them. The Quick Launch toolbar is nice, as is the list of frequently used programs on the Start menu. I want a place where I can put system-oriented commands, though, so I like to put those commands on My Computer's shortcut menu. Then I can display the My Computer icon on the desktop and they're one mouse click away. You learned how to show the icon in the section "Hiding Desktop Icons."

To add commands to My Computer's shortcut menu, edit its class registration, which is in HKCR\CLSID\{20D04FE0-3AEA-1069-A2D8-08002B30309D}. Add the command to this key's shell subkey. For example, after installing Microsoft Tweak UI, which you learn about in Chapter 5, "Mapping Tweak UI," I like to add a command to My Computer's shortcut menu that opens Tweak UI. So I add the branch tweak\command to My Computer's class registration. I set the default value of tweak to Tweak UI, the menu item text, and the default value of command to C:\Windows\System32\Tweakui.exe, the path and file name of Tweak UI. After customizing the class registration for My Computer, starting Tweak UI is fast: Right-click My Computer, and then click Tweak UI.

The following INF file automates this setting. First install Tweak UI. Then save this script to the file Tweakui.inf, right-click the file, and then click Install. (Again, you can download these sample scripts from http://www.honeycutt.com.) See Chapter 9, "Scripting Registry Changes," for other ways to script this hack. You can uninstall these settings in Add Or Remove Programs.

Listing 4-2: Tweakui.inf

start example

 [Version] Signature=$CHICAGO$ [DefaultInstall] AddReg=Reg.Settings AddReg=Reg.Uninstall CopyFiles=Inf.Copy [DefaultUninstall] DelReg=Reg.Settings DelReg=Reg.Uninstall DelFiles=Inf.Copy [Reg.Settings] HKCR,CLSID\{20D04FE0-3AEA-1069-A2D8-08002B30309D}\shell\tweak HKCR,CLSID\{20D04FE0-3AEA-1069-A2D8-08002B30309D}\shell\tweak,,,"%MENUITEM%" HKCR,CLSID\{20D04FE0-3AEA-1069-A2D8-08002B30309D}\shell\tweak\command\ ,,0x20000,"%SYSTEMROOT%\System32\Tweakui.exe" [Reg.Uninstall] HKLM,Software\Microsoft\Windows\CurrentVersion\Uninstall\%NAME% HKLM,Software\Microsoft\Windows\CurrentVersion\Uninstall\%NAME%,DisplayName\ ,,"%NAME%" HKLM,Software\Microsoft\Windows\CurrentVersion\Uninstall\%NAME%,UninstallString\ ,,"Rundll32.exe setupapi.dll,InstallHinfSection DefaultUninstall 132"\ "%17%\Tweakui.inf" [Inf.Copy] Tweakui.inf [DestinationDirs] Inf.Copy=17 [SourceDisksNames] 55=%DISKNAME% [SourceDisksFiles] Tweakui.inf=55 [Strings] NAME     = "Jerry's Tweak UI Shortcut" MENUITEM = "Tweak UI" DISKNAME = "Setup Files" 

end example

You can add any command to any shortcut menu, and that command doesn't have to edit, print, or do anything at all with the menu's target. My Computer is a good place to park system-oriented commands like Tweak UI, but you could also put them on another object's shortcut menu, such as Recycle Bin, if you don't display the My Computer icon on the desktop.

Open Command Prompts at Folders

Another favorite customization, and the one I probably use the most, enables me to quickly open an MS-DOS command prompt with the targeted folder set as the current working directory. I add the command C:\WINDOWS\System32\cmd.exe /k cd "%1" to the Directory and Drive program classes. Then I right-click a folder and click CMD Prompt Here to open a command prompt with that folder set as the current working directory. This is a real time saver. Here are the settings to add to HKCR\Directory (repeat these settings in HKCR\Drive):

  • In HKCR\Directory\shell, create the subkey cmdhere.

  • In HKCR\Directory\shell\cmdhere, set the default value to CMD Prompt Here. This is the text you'll see on the shortcut menu.

  • In HKCR\Directory\shell\cmdhere, create the subkey command.

  • In HKCR\Directory\shell\cmdhere\command, set the default value to C:\Windows\System32\cmd.exe /k cd "%1".

The following script automatically adds this command to the Directory and Drive program classes. Save it to the text file Cmdhere.inf, right-click it, and then click Install. To understand how this script works, see Chapter 9, "Scripting Registry Changes." Remove these settings using Add Or Remove Programs.

Listing 4-3: Cmdhere.inf

start example

 [Version] Signature=$CHICAGO$ [DefaultInstall] AddReg=Reg.Settings AddReg=Reg.Uninstall CopyFiles=Inf.Copy [DefaultUninstall] DelReg=Reg.Settings DelReg=Reg.Uninstall DelFiles=Inf.Copy [Reg.Settings] HKCR,Directory\Shell\Cmdhere HKCR,Directory\Shell\Cmdhere,,,"%MENUITEM%" HKCR,Directory\Shell\Cmdhere\command,,,"%11%\cmd.exe /k cd ""%1""" HKCR,Drive\Shell\Cmdhere HKCR,Drive\Shell\Cmdhere,,,"%MENUITEM%" HKCR,Drive\Shell\Cmdhere\command,,,"%11%\cmd.exe /k cd ""%1""" [Reg.Uninstall] HKLM,Software\Microsoft\Windows\CurrentVersion\Uninstall\%NAME% HKLM,Software\Microsoft\Windows\CurrentVersion\Uninstall\%NAME%,DisplayName\ ,,"%NAME%" HKLM,Software\Microsoft\Windows\CurrentVersion\Uninstall\%NAME%,UninstallString\ ,,"Rundll32.exe setupapi.dll,InstallHinfSection DefaultUninstall 132"\ "%17%\Cmdhere.inf" [Inf.Copy] Cmdhere.inf [DestinationDirs] Inf.Copy=17 [SourceDisksNames] 55=%DISKNAME% [SourceDisksFiles] Cmdhere.inf=55 [Strings] NAME     = "Jerry's CMD Prompt Here" MENUITEM = "CMD &Prompt Here" DISKNAME = "Setup Files" 

end example

Rooting Windows Explorer at a Folder

The idea behind this customization is to open Windows Explorer without all the usual clutter so you can focus on a single folder. Add the command explorer.exe /e,/root,/idlist,%I to the Folder program class's shell subkey. Then right-click any folder, choose the command you added, and another Windows Explorer window opens with that folder rooted at the top of the left pane.

Here are the settings you add to the Folder program class:

  • In HKCR\Folder\shell, create the subkey fromhere.

  • In HKCR\Folder\shell\fromhere, set the default value to Explore from Here. This is the text you'll see on the shortcut menu.

  • In HKCR\Folder\shell\fromhere, create the subkey command.

  • In HKCR\Folder\shell\fromhere\command, set the default value to explorer.exe /e,/root,/idlist,%I.

The following script automatically adds this command to the Folder program class. Save it to the text file Fromhere.inf, right-click it, and then click Install. To understand how this script works, see Chapter 9, "Scripting Registry Changes." Remove these settings using Add Or Remove Programs.

Listing 4-4: Fromhere.inf

start example

 [Version] Signature=$CHICAGO$ [DefaultInstall] AddReg=Reg.Settings AddReg=Reg.Uninstall CopyFiles=Inf.Copy [DefaultUninstall] DelReg=Reg.Settings DelReg=Reg.Uninstall DelFiles=Inf.Copy [Reg.Settings] HKCR,Folder\shell\fromhere HKCR,Folder\shell\fromhere,,,"%MENUITEM%" HKCR,Folder\shell\fromhere\command,,,"explorer.exe /e,/root,/idlist,%I" [Reg.Uninstall] HKLM,Software\Microsoft\Windows\CurrentVersion\Uninstall\%NAME% HKLM,Software\Microsoft\Windows\CurrentVersion\Uninstall\%NAME%\ ,DisplayName,,"%NAME%" HKLM,Software\Microsoft\Windows\CurrentVersion\Uninstall\%NAME%\ ,UninstallString,,"Rundll32.exe setupapi.dll,InstallHinfSection DefaultUninstall 132"\ "%17%\Fromhere.inf" [Inf.Copy] Fromhere.inf [DestinationDirs] Inf.Copy=17 [SourceDisksNames] 55=%DISKNAME% [SourceDisksFiles] Fromhere.inf=55 [Strings] NAME     = "Jerry's Explore from Here" MENUITEM = "Explore from &Here" DISKNAME = "Setup Files" 

end example

Adding InfoTips to Program Classes

I like InfoTips; you might not. Position the mouse pointer over an object in the user interface, and Windows XP displays the InfoTip associated with it in a small yellow box. For documents, the InfoTip typically includes the type of document, the date of its last modification, its size, and so on. You can further customize InfoTips, though.

Windows XP uses the REG_SZ value InfoTip to display InfoTips. The operating system uses this value it finds in the class registration or program class to which the object belongs. For example, if you position the mouse pointer over a file with the .doc file extension, Windows XP looks in the associated program class Wordpad.Document.1 for the value InfoTip. If it doesn't find the value there, it uses the value InfoTip that it finds in HKCR\*. The default value of that is prop:Type;DocAuthor;DocTitle;DocSubject;DocComments; Write;Size.

Thus, you can customize individual classes or create an InfoTip that applies to all classes. If you're after a specific object or file type, add the REG_SZ value InfoTip to that specific class registration or program class. Otherwise, customize the value InfoTip in HKCR\* to see that tip for all file classes.

So what does all that mean? The notation prop: name indicates to Windows XP that it should use the document property name in the InfoTip. Thus, the value you just saw means that Windows XP should display the document properties Type, DocAuthor, DocTitle, DocSubject, DocComments, Write, and Size in the InfoTip. You can also set InfoTip to an exact string that you want Windows XP to display when users position the mouse pointer over objects of that particular class. For example, you can set InfoTip for the txtfile program class to This is a text file, and that's what Windows XP displays when users position the mouse pointer over text files. Windows XP ignores any property in the InfoTip that the document doesn't define, and InfoTips can be up to six lines long. The following list shows just some of the document properties that you can add to an InfoTip (available properties depend on each individual program class):

  • Access

  • Album

  • Artist

  • Attributes

  • Bit Rate

  • CameraModel

  • Company

  • Copyright

  • Create

  • Dimensions

  • DocAuthor

  • DocCategory

  • DocComments

  • DocPages

  • DocSubject

  • DocTitle

  • Duration

  • FileDescription

  • FileVersion

  • Genre

  • LinkTarget

  • Name

  • Owner

  • ProductName

  • ProductVersion

  • Protected

  • Size

  • Status

  • Track

  • Type

  • WhenTaken

  • Write

  • Year

Note 

A related value is TileInfo. The contents of this value are the same as the contents of InfoTip. Windows XP displays TileInfo next to icons in Tile view. You're limited to two lines, however, so make good use of the space you have. I don't like the default value of TileInfo in most cases; I prefer to display more useful information such as a file's attributes. Thus, I like to set the value HKCR\*\TileInfo to prop:Type;Attributes, which is more useful to me. Although you don't have to log off and back on to Windows XP to see changes you make to InfoTip, you do have to log off of Windows XP to see changes you make to TileInfo.

start sidebar
Customizing Folders with Desktop.ini

This customization only marginally involves the registry, but it's too good to leave out. This chapter shows you how to customize files and other objects you see in the user interface, but customizing individual folders is good, too. For example, you might have a folder in My Documents that you want to stand out from others.

You do that by creating the file Desktop.ini in the folder. You can customize folders numerous ways using this file, but the two most interesting are setting unique icons for folders and displaying InfoTips when users position the mouse pointer over them. In this sample Desktop.ini file, the value IconFile points to the file containing the icon I want Windows Explorer to display for the folder. The value IconIndex is the index number of the icon, starting with 0, which is the first icon in the file. If you use an icon file instead of a DLL or EXE file, put the path of the file in IconFile and set IconIndex to 0. InfoTip is the text that I want Windows Explorer to display when I position the mouse pointer over the folder.

 [.ShellClassInfo] IconFile=C:\Windows\Regedit.exe IconIndex=0 InfoTip="Manuscripts for my latest registry book." 

Set the Desktop.ini file's Hidden And System attribute by typing the command attrib +s +h filename in the Run dialog box. You also set the folder's System attribute by typing the command attrib +s foldername in the Run dialog box. Figure 4-5 shows what the folder Registry Book looks like after creating this Desktop.ini file in it and setting the file and folder's attributes. Now whenever I position the mouse pointer over the folder, I am reminded of the important task at hand.

click to expand
Figure 4-5: When I hold the mouse pointer over the Registry Book folder, I see the text Manuscripts for my latest registry book.

end sidebar



Microsoft Windows XP Registry Guide
Microsoft Windows XP Registry Guide (Bpg-Other)
ISBN: 0735617880
EAN: 2147483647
Year: 2005
Pages: 185

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net