File Types

Files with a shared common file name extension (.doc, .html, and so on) are the same type. When developing an application that uses files, you can use existing, well-defined file types. For example, if you create a new text editor, then you can use the existing .txt file type. In other cases, you might need to create a new file type.

This topic is organized as follows:

Public Versus Private File Types

Public file types are also known as popular or contentious types because competing applications might want to be associated with these file types.

Some characteristics of public file types include:

  • Applications from multiple vendors are likely to handle them.
  • They are typically defined by standards bodies, or promoted by their defining organizations as interchange formats.
  • They are often exchanged between computers and users for diverse purposes.
  • They need to be supported on many different platforms.

Some examples of file types that are considered public are the image formats .png, .gif, .jpeg, and .bmp, and the audio formats .wav, .mp3, and .au.

Unlike public file types, private or proprietary file types typically have a format that is implemented and understood by only one application or vendor. As a result, private file types are typically not prone to conflicts between applications. Some file types may start their life as private file types, but later become public file types.

Note  Microsoft Windows does not differentiate between public and private file types. The distinction is relevant only in making decisions about your choice of file type registration.

Choosing a File Type Extension

Your file type is identified by the file name extension.

To define a new file type:

  1. Choose a long file name extension that you want to use to identify the file type. For more information, see File Type Handlers.
  2. Check the Internet Assigned Numbers Authority (IANA) MIME database to determine whether the file name extension is already associated with another application.
  3. We recommend that you also define a MIME type when defining a new public file type, and register it with IANA MIME.

    For more information, see the >IANA World Wide Web link Web site.

Registering a File Type

If you plan to associate the file with an existing application, locate an application ProgID in the registry. To associate the file type with a new application, define a ProgID for your application. For information about defining a new ProgID, see Programmatic Identifiers.

File name extension subkeys have the following general form: extension=ProgID. The registry stores the file name extension subkeys under HKEY_CLASSES_ROOT .

It is important to include the leading period when creating file type subkey entries in the registry. For example, if you want a file type with the short extension .myp and the long extension .myp-file to open with an application called MyProgram, use the following syntax:

HKEY_CLASSES_ROOT
     .myp
          (Default) = ApplicationVendor.MyProgram
     .myp-file
          (Default) = ApplicationVendor.MyProgram
     ApplicationVendor.MyProgram
          (Default) = MyProgram Application

As demonstrated in this example, if you also register a short file name extension, you should create a subkey for the short extension as well. For more information, see File Type Handlers.

Setting Optional Subkeys and File Type Extension Attributes

File type extension entries in the registry have several optional subkeys and attributes.

The file type extension entries that are used by file associations are as follows:

ValueAction
Default ValueSet the default value of the extension subkey to the ProgID to which it is linked. This is a registry string (REG_SZ).
Content TypeSet this string to the file type's MIME content type.
OpenWithListThis subkey contains one or more application subkeys for applications to appear in the Open with dialog box entry for the file type.
OpenWithProgidsThis subkey contains a list of alternate ProgIDs for this file type. The programs for these ProgIDs appear in the Open With dialog box. Whenever a program takes over this file type by changing the default value, it should also add an entry to this list.
PerceivedType

Set this string to the PerceivedType to which the file belongs, if any. This string is not used by Windows versions prior to Windows Vista. For more information, see Perceived Types and Application Registration.

The general form of a file name extension subkey is as follows. All entry types are REG_SZ.

HKEY_CLASSES_ROOT
     .ext
          (Default) = ProgID.ext.1
          Content Type = MIME content type
          PerceivedType = PerceivedType
          OpenWithList
               AlternateProgram1.exe
               AlternateProgram2.exe
          OpenWithProgids
               ProgID2.ext.1
               ProgID3.ext.1
          ProgID.ext.1
               shellnew

Important considerations in regard to file types include:

  • The HKEY_CLASSES_ROOT registry subtree is a view formed by merging HKEY_CURRENT_USER\Software\Classes and HKEY_LOCAL_MACHINE\Software\Classes . In general, HKEY_CLASSES_ROOT is intended to be read from but not written to. For more information, see HKEY_CLASSES_ROOT.
  • To register a file type globally on a particular computer, create an entry for the file type in HKEY_LOCAL_MACHINE\Software\Classes .
  • To make a file type registration visible to the current user only, create an entry for the file type in HKEY_CURRENT_USER\Software\Classes .
  • An application can provide its own implementation of a verb by registering the verb under the following subkey:

    HKEY_CLASSES_ROOT
         Applications
              ApplicationName.exe
                   shell
                        verb

    Subkeys of the verb subkey include the command line (command ) and the drop target method (DropTarget ).

  • Any time you create or change a file association, it is important to notify the system that you have made a change by calling SHChangeNotify, and specifying the SHCNE_ASSOCCHANGED event. If you do not call SHChangeNotify, then the change may not be recognized until after the system is rebooted.
  • To retrieve information regarding a file association from the registry, use the IQueryAssociations interface.

For a scenario that illustrates this procedure, see File Association Sample Scenario.

Defining File Type Attributes

Assigning file type attributes to an associated ProgID enables you to control some aspects of the file type's behavior. Prior to Windows Vista, these attributes could enable you to limit the extent to which the user could use the Folder Options property tab to modify various aspects of the file type, such as its icon or verbs.

File type attributes are binary flags specified as REG_DWORD or REG_BINARY values in the file type's associated ProgID subkey. To assign attributes for a file type, add an EditFlags entry to the file type's associated ProgID subkey and set it to the desired attribute value. The flags can be combined with a logical OR to form the single attribute value.

For a list of file type attributes and their hexadecimal values, and more details on programatically retrieving and setting these values, see FILETYPEATTRIBUTEFLAGS.

The following example shows the FTA_NoRemove (0x00000010) and FTA_NoNewVerb (0x00000020) attributes set for the .myp file type.

HKEY_CLASSES_ROOT
     .myp-file
          (Default) = ApplicationVendor.MyProgram
     ApplicationVendor.MyProgram
          (Default) = MyProgram Application
          EditFlags = 0x00000030

Adding an Application to the Open With Dialog Box

To ensure that an application is included in the Open with menu for a file type, include a reference to the application in either the OpenWithProgids or OpenWithList subkey for the file type as shown here.

HKEY_CLASSES_ROOT
     .ext
          OpenWithList
               AlternateProgram1.exe
               AlternateProgram2.exe
          OpenWithProgids
               ProgID2.ext.1
               ProgID3.ext.1

The OpenWithProgids subkey is preferred to OpenWithList to identify an application. For more information on these subkeys, see the Setting Optional Subkeys and File Type Extension Attributes section.

Excluding an Application from the Open With Dialog Box for Unassociated File Types

When a user attempts to open a file that is not a member of any registered file type (that is, an unknown file type), or when a user selects Open with or Open with -> Choose default program from a file's shortcut menu, the Shell presents a submenu or dialog box that enables the user to specify the program to open the file.

By default, any application registered as a subkey of HKEY_CLASSES_ROOT\Applications is presented in the Open With dialog box. These applications are presented in Open With regardless of whether the application is registered to handle the file type. There are two ways to restrict an application's presence in the Open With dialog box when an application should not or cannot be used to open file types that it is not registered to handle. Those two ways are:

To restrict an application's presence in the Open With dialog box, use one of the following two ways:

  1. Add a NoOpenWith entry to the application's subkey. When an application uses a file type, Windows records that information to build the Recommended Programs list; this list is presented in the Open with submenu as shown here:

    Shortcut menu with the Open With submenu shown

    These applications are also shown in the Recommended Programs portion of the Open With dialog box as shown here:

    Open With dialog box with Recommended Programs

    Applications can disable this tracking by specifying a NoOpenWith value under the application's subkey. If an application has registered itself in the OpenWithList or OpenWithProgIDs for the file type, it will appear in the Recommended Programs list even if the NoOpenWith entry is set. But the user can still choose to manually browse to any executable file.

    The NoOpenWith entry is an empty REG_SZ value as shown in the following example.

    HKEY_CLASSES_ROOT
         Applications
              MyProgram.exe
                   NoOpenWith

    NoOpenWith also prevents the pinning of a file to the application's Jump List through drag-and-drop, unless the application is specifically registered to handle that file type.

    Also, NoOpenWith prevents the common file dialog and any call to SHAddToRecentDocs from adding any file to the application's Jump List unless the application is specifically registered to handle that file type.

  2. The second way to restrict an application's presence in the Open With dialog box is to use the SupportedTypes subkey to explicitly list those extensions that the application can open. This restricts the appearance of the application in the Open With dialog box for only those file types that it can open. It also causes the application to appear in the Recommended Programs list as shown in the previous screen shot.

    This is particularly useful if an application can save a file as a certain file type but cannot open that file type. An application should also set the FOS_DONTADDTORECENT flag through IFileDialog::SetOptions when calling the Save dialog box. This keeps the item from being added to the Recent or Frequent portions of a Jump List. It also blocks the application from being tracked under the OpenWithList registry.

    Each supported extension is added as an entry under the SupportedTypes subkey as shown in the following example. The entries are of type REG_SZ or REG_NULL, with no associated values.

    HKEY_CLASSES_ROOT
         Applications
              ApplicationName
                   SupportedTypes
                        .ext1
                        .ext2
                        .ext3

    If a SupportedTypes subkey is provided, only files with those extensions are eligible for pinning to the application's Jump List or for being tracked in an application's Recent or Frequent destinations list.

    The NoOpenWith entry overrides the SupportedTypes subkey and hides the application in the Open With dialog box.

Deleting Registry Information During Uninstallation

When uninstalling an application, the ProgIDs and most other registry information associated with that application should be deleted as part of the uninstallation. However, applications that have taken ownership of a file type (by setting the Default value of the file type's HKEY_CLASSES_ROOT\.extension subkey to the ProgID of the application) should not attempt to remove that value when uninstalling.

Leaving that data in place for the Default value avoids the difficulty of determining whether another application has taken ownership of the file type and overwritten the Default value after the original application was installed. Windows respects the Default value only if the ProgID found there is a registered ProgID. If it is not, it is ignored.

Note that other file-type ownership information is stored in the HKEY_CURRENT_USER subtree and it also is used only that it references is registered. Therefore, this data also does not need to be removed during an application's uninstallation.

For instance, the following registry example shows the state of the registry before an application is uninstalled:

HKEY_CLASSES_ROOT
     .mp3
          (Default) = YourProgID
     YourProgID
          shell
               open
                    command
                         (Default) = yourapp.exe %1

The following example shows the state of those same registry entries after the application has been uninstalled.

HKEY_CLASSES_ROOT
     .mp3
          (Default) = YourProgID
     YourProgID subkey removed

File Types That Support Open Metadata

In Windows 7 and later, the file types listed in the following table support open metadata.

File typeFile name extension
Office 2007 Documentsdocx, xlsx, pptx
Office 97-2003 Documentsdoc, xls, ppt
Saved Searchsearch-ms
Windows media based formats (Advanced Streaming Format (ASF) container)wmv, wma
MP4 (property handler)mp4, m4a, m4v, mp4v, m4p, m4b, 3gp, 3gpp, 3gp2, mov

Related Topics

Tags :


Community Content

Chris_Guzak
docs missing for keys under HKCR\Applications\
HKCR\Applications\<AppName.exe>\SupportedTypes
".ext1"=""
".ext2"=""

lets an application provide an include list of file types that it supports; this avoids the app being added to the open with menu for a file type that it can not open. this is useful if an application can save a particular file type but not open it. in addition use FOS_DONTADDTORECENT when calling the file save dialog to avoid the file type being added to the list of types that the application can support via OpenWith.

HKCR\Applications\<AppName.exe>\shell\<verb name>

lets an applicaiton provide the verb implementation for the verb listed. this can include the cmd line method (shell\<verb>\command=<command line>, the DropTarget method, or others.
Tags :

Page view tracker