Recipe 5.14. Customizing Right-Click Menu Choices in Windows Explorer


Problem

You want to customize the pop-up shortcut menu that appears when you right-click on a file in Windows Explorer. The pop-up menu differs according to the program that you right-click on. So if you right-click on a graphics file, for example, one set of programs will appear on the menu, and if you click on a text file, a different set of programs will appear on the menu. You want to be able to change the choices that appear for specific file types. And you want to add new choices to the pop-up menu, so that you can do things such as easily move and copy files between folders.

Solution

Using a graphical user interface

It's easy to add choices to the right-click pop-up menu for specific file types. Let's say that you want to add a shortcut menu item that would allow .gif files to be opened with the graphics viewer and editor IrfanView. Here's how to do it:

  1. From Windows Explorer, choose Tools Folder Options File Types.

  2. Choose Advanced New. You'll see the New Action dialog box shown in Figure 5-13.

  3. In the Action box, type in the text that you want to appear on the shortcut menu, for example, Open with IrfanView.

  4. In the Application used to perform action box, enter the executable program you want to open the file with, including the full path. Surround it with quotation marks. Then leave a space and type in "%1". The "%1" is a placeholder for the name of the file on which you right-clicked. In our instance, the entire string would look like this: "C:\Program Files\i_view32.exe" "%1".

  5. Click on OK. The change will take place immediately, and the new command will appear on the shortcut menu for the specified file type.

Figure 5-13. Use the New Action dialog box to add an item to a file's shortcut menu


Add and remove destinations for the Send To option

A particularly useful item on the right-click context menu is the Send To option, which allows you to send the file you've selected to anyone of a list of programs or locations, for example to a drive, folder, or program. When you install new programs, some install various options on this menu choice. You can, however, easily delete or add to options on the menu. In Windows Explorer go to C:\Documents and Settings\<User Name>\SendTo, where <User Name> is your user name. The folder will be filled with shortcuts to all the locations that you find on your Send To context menu. To remove an item from the Send To menu, delete the shortcut from the folder. To add an item to the menu, add a shortcut to the folder by highlighting the folder, choosing File New Shortcut, and following the instructions for creating a shortcut. The new setting will take effect immediately; you don't have to exit Windows Explorer for it to go into effect.

Using the Registry

You can use the graphical user interface to add a menu choice to the Open With dialog box for specific file types. But if you want to add the same shortcut menu item to every type of file, you'll have to use the Registry. Here's how to do it:

  1. Open the Registry Editor and go to HKEY_CLASSES_ROOT\*.

  2. Create a new subkey called Shell if it doesn't yet exist.

  3. Create a new subkey under Shell and name it what your new command will be, for example, OpenWithIrfanView.

  4. For the default value of the new subkey, type in the text that you want to appear on the shortcut menu, for example, Open with IrfanView.

  5. Create a new subkey named Command under the subkey that you just created.

  6. For the default value of the Command subkey, enter the command string that you want to be executed when the shortcut menu item is chosen, for example, "C:\Program Files\i_view32.exe" "%1".

  7. Exit the Registry. The new shortcut menu item should be immediately available, although you may need to reboot in order for it to take effect.

Cleaning up Explorer's Open With options

The previous parts of the recipe will let you add items to the Open With menu. But what if you find that the Open With menu for a particular file type is filled with too many options, or there are programs that you don't want to be there? Use the Registry to clean it up:

  1. Open the Registry Editor and go to HKEY_CURRENT_USER\Software\Microsoft\ Windows\CurrentVersion\Explorer\FileExts.

  2. Look for the file extension whose Open With list you want to edit and find its OpenWithList subkey, for example, HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\ .bmp\OpenWithList.

  3. The subkey will have an alphabetical list of string values. Open each value and examine the value data. It will be the name of one of the programs on the Open With list, such as Winword.exe.

  4. Delete any entry that you don't want to appear. Be sure to delete the string listing itself. In other words, if in the a string value, the value data was Winword.exe, delete the entire a string listing and not just the value.

  5. Go to HKEY_CURRENT_USER\.bmp\OpenWithList and HKEY_CURRENT_USER\.bmp\OpenWithProgids and remove any offending entries.

  6. Exit the Registry. The change will take effect immediately.

Add Copy To Folder and Move To Folder context menu options

A substantial amount of the time, when you open Windows Explorer, you're going to want to perform one of two functions: Move a file between folders or copy a file to another folder. But doing these two simple tasks requires a fair amount of dragging files, or manually copying and pasting them. However, you can use the Registry to add Copy To Folder and Move To Folder options to the right-click context menu. Then, when you right-click on a file, you can chose either option from the menu and you'll be able to browse to any place on your hard disk to copy or move the file to, and then send the file there. To do it:

  1. Run the Registry Editor (see Chapter 9, Working with the Registry), and go to HKEY_CLASSES_ROOT\AllFilesystemObjects\shellex\ContextMenuHandlers.

  2. Create a new key called Copy To. Set the value to {C2FBB630-2971-11d1-A18C-00C04FD75D13}.

  3. Create another new key called Move To. Set the value to {C2FBB631-2971-11d1-A18C-00C04FD75D13}.

  4. Exit the Registry. The changes should take effect immediately. The Copy To Folder and Move To Folder options will appear. When you right-click on a file and choose one of the options, you'll be able to move or copy the file using a dialog box like that shown in Figure 5-14.

Figure 5-14. When you choose the Copy To Folder option on the right-click context menu, you'll use this dialog box to specify where you want the file copied


Open the command prompt from the right-click menu

XP may be a GUI, but that doesn't mean that you don't need the command prompt at times. There may be times when you want to open the command prompt from the right-click menu. Frequently, when you use the command prompt, you're going to want to perform an action from your current folder, so it would be nice to be able to open the command prompt to the current folder. For example, if you were to right-click on the C:\Current Work folder, you could then choose to open a command prompt at C:\Current Work. To add an option to the right-click menu:

  1. Run the Registry Editor (see Chapter 9, Working with the Registry), and go to HKEY_LOCAL_MACHINE/Software/Classes/Folder/Shell.

  2. Create a new key called Command Prompt.

  3. For the default value, enter whatever text you want to appear when you right-click on a folder; for example, Open Command Prompt.

  4. Create a new key beneath the Command Prompt key called Command.

  5. Set the default value to Cmd.exe /k pushd %L. That value will launch Cmd.exe, which is the XP command prompt. The /k switch puts the prompt into interactive mode that is, it lets you issue commands from the command prompt; the command prompt isn't being used to issue only a single command and then exit. The pushd command stores the name of the current directory, and the %L uses the name of that stored directory to start the command prompt at it.

  6. Exit the Registry. The new menu option will show up immediately. Note that it won't appear when you right-click on a file it only shows up when you right-click on a folder.

Using downloadable software

Download and install a free copy of Microsoft's Open Command Window Here PowerToy from http://www.microsoft.com/windowsxp/pro/downloads/powertoys.asp. When you get to the page, look for the Open Command Window Here section. Click on the link next to CmdHere.exe. After you download it, run CmdHere.exe, and the option will be added to the right-click context menu.

Discussion

When you right-click on a file in Explorer, the shortcut menu that appears includes a list of programs with which you can open the file. To open the file with a given program, choose the program, and you'll be able to open the file with it. This pop-up menu differs according to the program that you right-click on. So if you right-click on a graphics file, for example, one set of programs will appear on the menu, and if you click on a text file, a different set of programs will appear on the menu.

Some programs, when you install them, automatically put themselves on that pop-up menu. But not all do. So this recipe lets you customize the pop-up menu so that certain programs appear on it for certain file types. It also lets some programs appear on every file type. And it allows you to remove some programs from appearing when you right-click on a file.

See Also

PC Magazine has an excellent utility, ContextMenu Plus, that makes it easy to edit, add, or remove menu commands from any Windows context menu. Get it at http://www.pcmag.com/article2/0,1759,1554248,00.asp. You can only download it if you're a subscriber to the PC Magazine utilities library; if you're a subscriber, it's free.



Windows XP Cookbook
Windows XP Cookbook (Cookbooks)
ISBN: 0596007256
EAN: 2147483647
Year: 2006
Pages: 408

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