File Extension Association, Add new action to file types, and Handle files opened from Explorer

Posted on 1997-12-02
Last Modified: 2013-12-03
This is a three part question.

I am writing a program, in which I must be able to handle .txt files, and a file type the program creates, .cod

1. How do I have setup automatically associate .cod files with my program so that when double-clicked on, they launch my program?

2. How do I have setup add an action to .txt files, so that when they are right-clicked on, an option appears that launches my program if selected?

3. Once I accomplish that, how do I make my program handle the files that are opened with it? I manually associated .cod files with my program, and when double-clicked, my program is launced, but no actions occur.
Question by:yveinus
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment

Accepted Solution

MikeP090797 earned 100 total points
ID: 1443299
To register a file you need to modify the registery under HKEY_CLASSES_ROOT as described in this document:

If your application creates and maintains files, register entries for the file types that you expose directly to users and that you want users to be able to easily differentiate. For every file type you register, include at least two entries: a filename-extension key entry and an application (class) identification key entry.
If you do not register an extension for a file type, it will be displayed with the system’s generic file object icon, as shown in Figure 10.1, and its extension will always be displayed. In addition, the user will not be able to double-click the file to open it. (Open With will be the icon’s default command.)
Figure 10.1 System-generated icons for unregistered types
The Filename Extension Key
The filename extension entry maps a filename extension to an application identifier. To register an extension, create a subkey in the HKEY_CLASSES_ROOT key using the three-letter extension (including a period) and set its value to an application identifier.
    .ext = ApplicationIdentifier
For the value of the application identifier (also known as programmatic identifier or Prog ID), use a string that uniquely identifies a given class. This string is used internally by the system and is not exposed directly to users (unless explicitly exported with a special registry utility); therefore, you need not localize this entry.
Avoid assigning multiple extensions to the same application identifier. To ensure that each file type can be distinguished by the user, define each extension such that each has a unique application identifier. If you have utility files that the user does not interact with directly, you should still register an extension (and icon) for them, preferably the same extension so that they can be identified. In addition, mark them with the hidden file attribute.
The system provides no arbitration for applications that use the same extensions. So define unique identifiers and check the registry to avoid writing over and replacing existing extension entries, a practice which may seriously affect the user’s existing files. More specifically, avoid registering an extension that conflicts or redefines the common filename extensions used by the system. Examples of these extensions are shown in Table 10.1.
Table 10.1 Common Filename Extensions Supported by Windows
Extension      Type description

386      Windows virtual device driver
3GR      Screen grabber for MS-DOS–based applications
ACM      Audio compression manager driver
ADF      Administration configuration files
ANI      Animated pointer
AVI      Video clip
AWD      FAX viewer document
AWP      FAX key viewer
AWS      FAX signature viewer
BAK      Backed-up file
BAT      MS-DOS batch file
BFC      Briefcase
BIN      Binary data file
BMP      Picture (Windows bitmap)
CAB      Windows Setup file
CAL      Windows Calendar file
CDA      CD audio track
CFG      Configuration file
CNT      Help contents
COM      MS-DOS – based application
CPD      FAX cover page
CPE      FAX cover page
CPI      International code page
CPL      Control Panel extension
CRD      Windows Cardfile document
CSV      Command-separated data file
CUR      Cursor (pointer)
DAT      System data file
DCX      FAX viewer document
DLL      Application extension (dynamic-link library)
DOC      WordPad document
DOS      MS-DOS file (also extension for NDIS2 net card and protocol drivers)
DRV      Device driver
EXE      Application
FND      Saved search
FON      Font file
FOT      Shortcut to font
GR3      Windows 3.0 screen grabber
GRP      Program group file
HLP      Help file
HT      HyperTerminalTM file
ICM      ICM profile
ICO      Icon
IDF      MIDI instrument definition
INF      Setup information
INI      Initialization file (configuration settings)
KBD      Keyboard layout
LGO      Windows logo driver
LIB      Static-link library
LNK      Shortcut
LOG      Log file
MCI      MCI command set
MDB      File viewer extension
MID      MIDI sequence
MIF      MIDI instrument file
MMF      Microsoft Mail message file
MMM      Animation
MPD      Mini-port driver
MSG      Microsoft® Exchange mail document
MSN      Microsoft Network home base
NLS      Natural language services driver
PAB      Microsoft Exchange personal address book
PCX      Bitmap picture (PCX format)
PDR      Port driver
PF      ICM profile
PIF      Shortcut to MS-DOS–based application
PPD      PostScript® printer description file
PRT      Printer formatted file (result of Print to File option)
PST      Microsoft Exchange personal information store
PWL      Password list
QIC      Backup set for Microsoft Backup
REC      Windows Recorder file
REG      Application registration file
RLE      Picture (RLE format)
RMI      MIDI sequence
RTF      Document (rich-text format)
SCR      Screen saver
SET      File set for Microsoft Backup
SHB      Shortcut into a document
SHS      Scrap
SPD      PostScript printer description file
SWP      Virtual memory storage
SYS      System file
TIF      Picture (TIFF® format)
TMP      Temporary file
TRN      Translation file
TSP      Windows telephony service provider
TTF      TrueType® font
TXT      Text document
VBX      Microsoft Visual Basic® control file
VER      Version description file
VXD      Virtual device driver
WAV      Sound wave
WPC      WordPad file converter
WRI      Windows Write document
It is a good idea to investigate extensions commonly used by popular applications so you can avoid creating a new extension that might conflict with them, unless you intend to replace or superset the functionality of those applications.
The Application Identifier Key
The second registry entry you create for a file type is its class-definition (Prog ID) key. Using the same string as the application identifier you used for the extension’s value, create a key, and assign a type name as the value of the key.
    .ext = ApplicationIdentifier
    ApplicationIdentifier = Type Name
Under this key, you specify shell and OLE properties of the class. Provide this entry even if you do not have any extra information to place under this key; doing so provides a label for users to identify the file type. In addition, you use this entry to register the icon for the file type.
Define the type name (also known as the MainUserTypeName) as the human-readable form of its application identifier or class name. It should convey to the user the object’s name, behavior, or capability. A type name can include all of the following elements:
 1.      Company Name
Communicates product identity.
 2.      Application Name
Indicates which application is responsible for activating a data object.
 3.      Data Type
Indicates the basic category of the object (for example, drawing, spreadsheet, or sound). Limit the number of characters to a maximum of 15.
 4.      Version
When there are multiple versions of the same basic type, for upgrading purposes, you may want to include a version number to distinguish types.
When defining your type name, use title capitalization. The name can include up to a maximum of 40 characters. Use one of the following three recommended forms:
 1.      Company Name Application Name [Version] Data Type
For example, Microsoft Excel Worksheet.
 2.      Company Name-Application Name [Version] Data Type
For cases when the company name and application are the same — for example, ExampleWare 2.0 Document.
 3.      Company Name Application Name [Version]
When the application sufficiently describes the data type — for example, Microsoft Graph.
These type names provide the user with a precise language for referring to objects. Because object type names appear throughout the interface, the user becomes conscious of an object’s type and its associated behavior. However, because of their length, you may also want to include a short type name. A short type name is the data type portion of the full type name. Applications that support OLE always include a short type name entry in the registry. Use the short type name in drop-down and pop-up menus. For example, a Microsoft® Excel Worksheet is simply referred to as a “Worksheet” in menus.
To provide a short type name, add an AuxUserType subkey under the application’s registered CLSID subkey (which is under the CLSID key).
For more information about registering type names and other information you should include under the CLSID key, see the OLE documentation included in the Win32 SDK.
    .ext = ApplicationIdentifier
    ApplicationIdentifier = Type Name
        CLSID = {CLSID identifier}
        {CLSID identifier}
                2 = Short Type Name
If a short type name is not available for an object because the string was not registered, use the full type name instead. All controls that display the full type name must allocate enough space for 40 characters in width. By comparison, controls need only accommodate 15 characters when using the short type name.
When your program launches, it contains the file name that needed to be opened in it's command line. You can get the command line
using the Command$ function

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Suggested Courses
Course of the Month7 days, 2 hours left to enroll

623 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