Solved

What's the simplest way to just add a registry entry so your app has a context menu on right click

Posted on 2011-02-25
7
383 Views
Last Modified: 2012-05-11
I remember I used to have a registry file that I would run and it would make my .exe avaiable when you right click on a tif file in a windows environment.
0
Comment
Question by:silentthread2k
7 Comments
 
LVL 53

Expert Comment

by:Dhaest
ID: 34979394
Customizing Right-Click Menu Options in Windows
http://www.jfitz.com/tips/rclick_custom.html
0
 
LVL 12

Expert Comment

by:Mike
ID: 34979397
If you right click on the file, choose open with, and choose the program you want, you can have it open always with that program, or open once with that program.  Either way, once you do one of those, it will show up in the context menu under open with afterwards....
0
 
LVL 17

Expert Comment

by:Nik
ID: 34979418
Run Regedit
Navigate to HKEY_CLASSES_ROOT\Folder\shell
Add a new Key to the "Shell" Key and name it as you wish.
Give it a default value that will appear when you right click a folder, i.e. NewKey (use an "&" without the quotes, in front of any character and it will allow you to use the keyboard)
Click on the Key HKEY_CLASSES_ROOT\Folder\shell\NewKey
Add a New Key named Command
Set the (Default) value of the application you want to run
For example: c:\program files\internet explorer\iexplore.exe (Include the full path and parameters if you need them)
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 4

Accepted Solution

by:
loki_loki earned 500 total points
ID: 34979423
something like this?  This is for notepad but you can substitute your app
http://www.howtogeek.com/howto/windows-vista/add-open-with-notepad-to-the-context-menu-for-
all-files/
http://windowsxp.mvps.org/context_folders.htm gives all the possible registry locations.
0
 
LVL 38

Expert Comment

by:BillDL
ID: 34981050
Hi silentthread2k

If you have several applications that you regularly use to view TIF files, but do not want to associate the TIF file extension to any of them other than what currently opens when you double-click a TIF file, then you should already have several programs listed on the Right-Click > "Open With" menu.

The new programs should be added to the list after you use the Right-Click > "Open With ..." > Select a Program from the list > Scroll to or "Browse" to a program executable > click OK.

Be sure to *** UNTICK *** the box in the "Open With" dialog entitled "Always use the selected program to open files of this type", OR ELSE the program you choose will become the program that opens when you double-click a TIF file.

Repeat this for all the programs that you sometimes have the need to open TIF files in, and your new "Open With" listing is as quick to get to as adding yet another item to what may already be a lengthy Right-Click menu.

Of course, doing this too often for different programs, especially when experimenting to see what programs can and cannot open a particular file type, will add clutter to your "Open With" menu.   Ramesh Srinivasan (same author as loki_loki's 2nd link in the comment above) explains how to clear out this unwanted clutter here:
http://windowsxp.mvps.org/openwith.htm
He supplies a useful "File Extension Info" tool to help you with it here:
http://windowsxp.mvps.org/fileextinfo.htm
and yet another one that allows you to create your own entries here:
http://windowsxp.mvps.org/openwithadd.htm

Remember that the Right-Click > "Preview" option for most image file types will open in the Windows Picture and Fax Viewer in Windows XP, so leave that in place if you are tempted to mess with 3rd party applications that thin out the "Open With" menu.

Some people (me included) like the Right-Click > "Open With" menu option, while some people don't.  It's a personal choice, as is the preference for any utilities to view and/or manage file extension properties.

My preference for viewing details of, and quickly opening regedit to the correct key for, file extensions, is "File Types Manager" by Nir Sofer (same author as the "ShellMenuView" and "ShellExView" utilities suggested in loki_loki's 2nd link):
http://www.nirsoft.net/utils/file_types_manager.html
Using that I can jump to the first relevant registry key.

A general rule of thumb and warning:

If the file type does not show, or shows but will not allow you to Edit it, in the Control panel > Folder Options > File Types dalog, then DON'T mess with it in Regedit, by merging reg files, or using 3rd party utilities.

Hope this helps

Bill

Read On If You Want To Know Some More Technical Info
========================================
(otherwise ignore everything below this).

What you should always remember is that a simple file type association exists in two main keys in your registry.  The first key is the one that shows the file extension with a dot, example:

HKEY_CLASSES_ROOT\.txt

The String value (REG_SZ) that shows in Regedit as (Default), or in an exported *.reg file as  @="string here", will be a common name that often reflects the actual file extension.  In the case of the *.TXT file, the (Default) string value is "txtfile".  That forms the basis of the OTHER key to scroll down and find:

HKEY_CLASSES_ROOT\txtfile

In THIS key, the (Default) string value is usually a more descriptive expression that defines what this type of file comprises.  It is in this key that you find the actual program association in the form of  "Shell\Verb\Command", where the "Verb" is the name of the action that shows in the Right-Click menu.

For example, for the *.TXT file the default action is "Open", and the corresponding key containing the path to the executable and any command parameters is:

HKEY_CLASSES_ROOT\txtfile\shell\open\command

The action that shows in bold text in your Right-Click menu for that file type, and is therefore your "Double-Click" action, is dictated by the (Default) string value right in the "Shell" key.  In an exported REG file for the *.TXT extension set to Notepad, you would see this:

 
Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\txtfile]
@="Text Document"
"FriendlyTypeName"=hex(2):value,comprising,long,string,of,paired,hex,numbers
"EditFlags"=dword:00000000
"BrowserFlags"=dword:00000008

[HKEY_CLASSES_ROOT\txtfile\DefaultIcon]
@=hex(2):reg_expand_sz,value,comprising,long,string,of,paired,hex,numbers

[HKEY_CLASSES_ROOT\txtfile\shell]
@="open" <--------------------------------*** Your Bold "Double-Click" action ***

[HKEY_CLASSES_ROOT\txtfile\shell\billpad_edit]
@="Open in BillPad"

[HKEY_CLASSES_ROOT\txtfile\shell\billpad_edit\command]
@="\"C:\\Program Files\\Billpad\\billpad.exe\" %1"

[HKEY_CLASSES_ROOT\txtfile\shell\open]

[HKEY_CLASSES_ROOT\txtfile\shell\open\command] <--- *** Corresponding "Open" Command
@=hex(2):reg_expand_sz,value,comprising,long,string,of,paired,hex,numbers

[HKEY_CLASSES_ROOT\txtfile\shell\print]

[HKEY_CLASSES_ROOT\txtfile\shell\print\command]
@=hex(2):reg_expand_sz,value,comprising,long,string,of,paired,hex,numbers

[HKEY_CLASSES_ROOT\txtfile\shell\printto]

[HKEY_CLASSES_ROOT\txtfile\shell\printto\command]
@=hex(2):reg_expand_sz,value,comprising,long,string,of,paired,hex,numbers

Open in new window



Note that my REG file contains an additional key:
HKEY_CLASSES_ROOT\txtfile\shell\billpad_edit
that I added so that I have another action named "Open in BillPad" for all *.txt files.

Windows and a lot of more recent application installers create the actual program command as a "REG_EXPAND_SZ" (or expanded string value) in the registry.  This is what shows in lines starting with    @=hex(2):   in an exported REG file.  For most this is gobbledegook and not something you could easily look at and amend or edit, but in Regedit when you double-click on a REG_EXPAND_SZ value it allows you to see the text equivalent.

There is nothing wrong in Windows XP with creating the value for your command as a standard String value (REG_SZ) which would show as follows if exported to a REG file:

@="\"C:\\Program Files\\Billpad\\billpad.exe\" %1"

Note that the REG file encloses the entire value in " " and, because the path to billpad.exe was deliberately double-quoted to avoid any potential issues with the space in the "Program Files" folder, those additional " " inside the ones applied to the Regedit export need to be handled literally, each is preceded by a \
For each backslash designating folders in the path to be treated literally, an extra \ is added in front of them too.

The %1 part of the command is a replaceable variable that stores the path to the file you are telling the program to open from the right-click or double-click. Sometimes this is enclosed in its own separate " " and sometimes not.  If a new action you created doesn't work at first, check whether you have a "%1" or a %1 and remove or add the " " to test again.  That's a common thing that causes people to tear out their hair in frustration.

Going back to the earlier bond between the:
HKEY_CLASSES_ROOT\.txt
@="txtfile"
and
HKEY_CLASSES_ROOT\txtfile
keys, you will no doubt notice a couple of value that should be explained.

As a REG File:
[HKEY_CLASSES_ROOT\.txt]
@="txtfile"
"Content Type"="text/plain"
"PerceivedType"="text"

As Shown in REGEDIT:
(Default)           REG_SZ      txtfile
ContentType    REG_SZ      text/plain
PerceivedType  REG_SZ      text

The (Default) value was discussed above when telling how to find the other key containing the actual file association settings.  ContentType and PerceivedType refer to the kind of content that a file of this type should contain, and the values are used in various ways including how to display such a file in a web browser.

There are some odd values under the OTHER key, eg for the *.txt file again:
[HKEY_CLASSES_ROOT\txtfile]

"EditFlags"=dword:00000000
"BrowserFlags"=dword:00000008

EditFlags             REG_DWORD           0x00000000 (0)
BrowserFlags      REG_DWORD           0x00000000 (8)

The EditFlags value is used to place restrictions on what you can see and edit for this file type in the Control Panel > Folder Options > File Types dialog, and the BrowserFlags value tells it whether to prompt for a download or display the contents of a file with this extension inside the web browser.

Tip:

If you have a *.REG file containing a REG_EXPAND_SZ value, shown with the   @=hex(2):   and want to see what that would be expanded to when read from the registry if you were to import it to your registry, I suggest creating a temporary bogus key in a copy of the REG file and merging that first.

Let's say you have the following in a REG file:

 
[HKEY_CLASSES_ROOT\zonkfile\shell\open\command]
@=hex(2):25,00,53,00,79,00,73,00,74,00,65,00,6d,00,52,00,6f,00,6f,00,74,00,25,\
  00,5c,00,73,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,5c,00,4e,00,4f,00,\
  54,00,45,00,50,00,41,00,44,00,2e,00,45,00,58,00,45,00,20,00,25,00,31,00,00,\
  00

Open in new window


What I do is make a copy of the REG file, open that in Notepad, and change the key to this:
[HKEY_CURRENT_USER\_TEST1]
and leave the rest as it is.

When merged to the registry that new key is very easy to find (it sits at the top of the sub-keys when you open HKEY_CURRENT_USER), you can immediately see what the command is, and can delete the "_TEST1" registry key.
0
 

Author Closing Comment

by:silentthread2k
ID: 34998442
Note: If anyone notices that they don't have shell under HKEY_CLASSES_ROOT\*\, then just create the shell key as well.

I did just that, because I found that I did not have shell. I had ShellEx.  So just create shell if you don't have it.
0
 
LVL 38

Expert Comment

by:BillDL
ID: 35007579
What exactly did you add under the key:
[HKEY_CLASSES_ROOT\*\shell]
after you created that key?  Just curious.

0

Featured Post

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Join & Write a Comment

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Windows 8 comes with a dramatically different user interface known as Metro. Notably missing from the new interface is a Start button and Start Menu. Many users do not like it, much preferring the interface of earlier versions — Windows 7, Windows X…
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now