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 3) - Customize Context Menus for Files

- 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:45:54 PM

3. Customize Context Menus for Files

A context menu (sometimes called a shortcut menu) is the little menu that appears when you use the right mouse button to click on a file, folder, application title bar, or nearly any other object on the screen. Most of the time, this menu includes a list of actions appropriate to the object on which you've clicked. In other words, the options available depend on the context.

The context menu for files, shown in Figure 4, is an assortment of standard actions common to all files (e.g., Copy, Paste, Delete, Rename, and Properties) plus one or more custom actions depending upon the type of file selected. Each of the custom actions is linked to an application: if you right-click a .txt file and select Open, Windows launches Notepad (by default) and instructs it to open the selected file. The default action—the action that is carried out when you double-click the file—appears in bold text in the context menu, and the rest of the actions are listed below. Among other things, this means you can have more than one program associated with a single file type.

Figure 4. Right-click a file to show its context menu; Windows Vista doesn't make it easy to customize the items you see here


In the case of .html files, for example, you could add an Edit action to open your favorite web page editor, a View with Firefox action, and a View with Internet Explorer action—all in addition to the default Open action.

Sounds great, right? Unfortunately, the File Types window—the tool found in earlier versions of Windows that lets you edit context menus from within Windows Explorer—is completely absent in Windows Vista. In its place is the extremely dumbed-down Set Associations window shown in Figure 5. Here, you can only choose default applications for your various file types, and in doing so, obliterate your applications' defaults or any custom context menus you've built (more on that later).

Figure 5. The Set Associations window—accessed through Control Panel → Default Programs → Associate a file type or protocol with a program—just plain sucks


There's a Registry key named Shell inside the file type key where all the magic happens. Each subkey of Shell corresponds to a single action in the file's context menu. The text that appears in the context menu (the label) is defined in the action key's (Default) value; if the (Default) value is empty, Windows Explorer just uses the name of the key (e.g., Open). Unfortunately, Windows Vista has two competing systems that determine the default actions for your file types; see the upcoming sidebar, "The Evils of UserChoice," for details.

The Evils of UserChoice

This is a new addition to Windows Vista, and a nasty one at that. If you right-click a file, select Open With, and then select a default application, Windows doesn't actually change the file type. Instead, Vista creates a new key for the filename extension in HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\, and then in that key, a UserChoice key with the full path of the program you've chosen, like this:

UserChoice


The point of the UserChoice key is to prevent applications from changing your defaults without your permission; as long as that UserChoice key exists, Windows ignores all the actions defined in the ordinary file type key.

Like so many other patchwork features in Windows, the UserChoice system just doesn't work that well. For one, any custom context menu items you've defined for a file type vanish if the corresponding extension ever shows up in the UserChoice key, with no means of retrieval without you having to manually edit the Registry. And the old trick of reinstalling an application to restore its file types won't work if the UserChoice key is involved (unless the installer is smart enough to deal with the UserChoice key).

The solution is to open the Registry Editor, navigate to HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer, and delete the FileExts key altogether. This will eliminate all UserChoice keys while leaving your file types intact. Thereafter, refrain from using the Open With menu or Control Panel to modify your file types, and your file associations will continue to behave as you expect.

Now, there's another, less obvious facet to the UserChoice key, one that may be a possible benefit for PCs with more than one user account. Traditional file types are stored in the HKEY_CLASSES_ROOT key, which is a subset of HKEY_LOCAL_MACHINE; this means your file types are the same for all users on your PC. But the UserChoice keys are buried in HKEY_CURRENT_USER branch, allowing each user to to have his or her own set of overrides. Of course, you can still delete your own FileExts key without affecting another user's overrides, but any subsequent changes you make to the file types in HKEY_CLASSES_ROOT will be put into action for all users right away.


Say you right-click a Microsoft Excel document (.xlsx file), and at the top of the menu that appears you see Open (in bold), New, and Print. If you open the Registry, you'll see that HKEY_CLASSES_ROOT\.xlsx points to HKEY_CLASSES_ROOT\Excel.Sheet.12, so you proceed to HKEY_CLASSES_ROOT\Excel.Sheet.12\Shell. Inside the Shell key, you'll see three subkeys named—you guessed it—New, Open, and Print. Add a new subkey to Shell, followed by the subkeys described shortly, and you'll get a new entry in the context menu for all files of the selected type.


The action shown in bold (usually Open) is called the default, and is the one carried out when you double-click the file. The (Default) value in the Shell key determines which action is the default; if (Default) is empty and there's more than one action, Windows assumes it's the one named Open. Otherwise, Windows just takes its best guess. You can, of course, change the default by setting the (Default) value to the name of any action key shown here.

Inside each action key is a subkey named command (and perhaps another named ddeexec). Inside the command key is a (Default) value that specifies the full path and filename of the program to run. Right-click an .xlsx file and select Open, and Windows runs the program listed in HKEY_CLASSES_ROOT\Excel.Sheet.12\shell\Open\command. For example:

"C:\Program Files\Microsoft Office\Office12\EXCEL.EXE" /e

The quotes around the full path and filename of the application accommodate the spaces, and tell Windows where the filename ends and the command-line options (such as /e, here) begin. Most of the time, though, the command-line contains a placeholder, %1, for the selected filename, like this:

"C:\Program Files\UltraEdit\UEDIT32.EXE" "%1"

When Windows opens this program, it passes the full path and filename of the selected file to the program by putting it in place of %1, like this:

"C:\Program Files\UltraEdit\UEDIT32.EXE" "C:\Users\Janeane\Desktop\readme.txt"

Now, that little option, %1, is the cause of a lot of problems in Windows' file types system, such as:
Application displays "not found" error.

The quotation marks are missing around the "%1" and the document you're trying to open has a space in its file- or pathname. Just add the quotes and try again.

Older application displays a "bad command line" error or something similar.

Not all programs respond well to the quotation marks around the "%1" parameter. Try taking them out if this happens.

Application doesn't open the file at all.

The "%1" parameter is missing altogether, or the application requires a different syntax. For instance, the Mozilla SeaMonkey web browser requires the -url parameter in front of %1, like this:

C:\Program Files\Mozilla SeaMonkey\seamonkey.exe -url "%1"

If you're not sure what your application needs, check the documentation or search Google for the application name and the words "command line.)

Application only opens a document if the application isn't already running.

This problem (and the next one) are caused by a background technology called Dynamic Data Exchange, or DDE, that allows Windows programs to communicate with one another. Windows sends a DDE signal to an application that's already running to instruct it to open the document. (If the application isn't already running, Windows launches it just like any other.) The specific DDE commands that the application needs are stored in the ddeexec Registry key, alongside the aforementioned command key (shown previously in Figure 3-12). If the ddeexec key is missing, Windows won't send the signal, and the program won't open your document. You can try rebuilding the ddeexec key if you can find documentation, but it's usually easier to just reinstall the application that owns the key. (Not all programs use DDE; don't bother creating the ddeexec key unless you are having this specific problem.)


Application opens the document twice.

The ddeexec key just described often causes more problems than it solves. Sometimes Windows sends the aforementioned DDE message and launches another copy of the program, which opens two document windows. If this happens, rename the ddeexec key to ddeexec.backup.

If an application has stopped responding (in other words, it crashed), it won't respond to Windows' DDE instructions to open your document, nor will Windows open a second copy of the program. To find out whether this is happening, right-click an empty portion of your task bar, select Task Manager, and click the Processes tab. If the program you're troubleshooting is there, highlight it and click End Process, and then try opening your document again.


At this point, you're probably thinking, "so, I have to type all these Registry keys by hand if I want the least bit of control over my file types?" If so, I laugh at you.

File Type Doctor, part of Creative Element Power Tools (available at http://www.creativelement.com/powertools/) and shown in Figure 6, lets you customize your context menus, change file type icons, and choose defaults.

Figure 6. File Type Doctor gives you the complete control over your file associations that Vista doesn't


In the File Type Doctor window, file types are organized by their names (shown in the righthand column) and by their corresponding filename extensions (shown in the lefthand column); click either column header to sort the list accordingly. The properties of the currently selected file type are shown on the right side of the window.

You can also right-click any file in Windows Explorer or on your desktop and select Edit File Type to customize the file's context menu in File Type Doctor on the fly.


Edit the name of the type—the text that appears in Windows Explorer's Type column and in the file's Properties window—by typing in the Name textbox at the top-right of the window. Click the Change button to choose an icon for all files of this type, or double-click the icon itself (to the left of the Change button) to choose from the icons in the default application executable (shown in bold in the Actions in right-click menu list).

File Type Doctor saves changes automatically as you make them. This makes it easy to test your context menus as you go, but it also means that most changes cannot be easily undone.


The Actions in right-click menu list on the right side shows all the context menu items registered for the selected file type. Click New to add a new item or click Edit (or double-click the item in the list) to modify the associated application and its options.

You can also remove unwanted context menu items by highlighting them here and clicking Remove. The list shows everything registered for the selected file type, as well as the perceived type. Shell extensions, explained in the upcoming sidebar, "Fix Wonky Shell Extensions," are shown in italicized font; these can be removed but not modified in the traditional sense.

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