Share via


File Types

Files with a common file extension (.doc, .html, and so on) are the same type. File type is also referred to as file class.

This topic discusses the following:

  • Defining a New File Type
  • Registering a New File Type
  • Defining File Type Attributes
  • Public vs. Private File Types
  • Excluding an Application from the Open With Dialog Box for Unassociated File Types

Defining a New File Type

The Shell uses a file's type to customize certain aspects of its treatment and handling. Some examples of file type customizations include:

  • Specifying the application used to open the file when double-clicked.
  • Adding commands to the context menu for a file type.
  • Specifying a custom icon for a file type.
  • Specifying a MIME content type to associate with a file type.
  • Specifying a perceived type for a file type.
  • Specifying one or more applications to associate with the Open With dialog box for a file type.

For a greater degree of control over the behavior of a file class, you can write one or more extension handlers. For more information, see Creating Shell Extension Handlers.

When you develop a new application that uses files, you can use existing, well-defined file formats. For example, if you create a new text editor, most likely you would use the existing .txt file type, rather than invent a new text file type. However, sometimes you need to invent one or more new file formats for use by a new application. To do this, define a new file type to describe each new file format and register it to take advantage of the file association.

Follow these steps to define and register a new file type.

  1. Decide if it is more appropriate to make the file type public or private. Public file types require extra consideration when dealing with file associations. For more information, see Public vs. Private File Types.

  2. Determine if a definition for the file type already exists. Check the Internet Assigned Numbers Authority (IANA) MIME database and other public file type databases on the Internet to determine whether any comparable file type is defined.

  3. Define the long and short extensions you want to use to identify the file type. For more information, see File Extensions.

  4. Define a MIME content type for the file and submit a registration document to the IANA for the file type, as described in Request for Comments (RFC) 2048. The file type registration document should include, at a minimum:

    • The defined file extensions.
    • The MIME content type.
    • A short description of the data and its uses.
    • Any binary signatures for the file type.
  5. Determine if a ProgID exists for the file type. If necessary, define a ProgID that is linked to the new file type. For information about defining a new ProgID, see Programmatic Identifiers.

  6. After you define a file type, you need to enter information that identifies it in the registry so that the Shell recognizes the new file type. Create an entry in the registry for each of the long and short file extensions. The registry stores the file extension entries under HKEY_CLASSES_ROOT . An entry has the general form: .extension=ProgID, including the leading period. This entry enables the Shell to identify the file type by looking at the file extension. For more information about adding file types, see Adding File Type Keys to the Registry.

  7. Register the ProgID. Each of these keys contains data about how the Shell treats files that belong to the file type. The ProgID contains information about the application associated with the file type, as well as optional subkeys that can customize an application's treatment of the file type. After the file type keys and the corresponding ProgID keys are in place, you can add subkeys to customize the behavior of the file type and its associated application. For a description of ProgID customization subkeys, see Programmatic Identifiers.

For a sample scenario of this procedure, see File Association Sample Scenario.

Registering a New File Type

The registry stores the file extension keys under HKEY_CLASSES_ROOT . These keys have the general form: .extension=ProgID. It is important to include the leading period when creating file type key 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
  • .myp-file
  • ApplicationnVendor.MyProgram

File type extension entries in the registry have several optional subkeys and attributes. Those used by file associations are:

  • Default Value. Set the default value of the extension key to the ProgID to which it is linked. This is a registry string (REG_SZ).
  • PerceivedType. Set this string to the PerceivedType to which the file belongs, if any. This string is not used by Microsoft Windows versions prior to Windows XP. For more information, see PerceivedTypes, SystemFileAssociations, and Application Registration.
  • Content Type. Set this string to the file type's MIME content type.
  • OpenWithProgids. This 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.
  • OpenWithList. This subkey contains one or more application keys for applications to appear in the Open With dialog box entry for the file type.

The general form of a file extension key is:

HKEY_CLASSES_ROOT

.ext

(Default) = ProgID.ext.1 (REG_SZ)
PerceivedType = PerceivedType (REG_SZ)
Content Type = mime content type (REG_SZ)

OpenWithProgids

  • ProgID2.ext.1
  • ProgID3.ext.1

OpenWithList

  • AlternateProgram1.exe
  • AlternateProgram2.exe

ProgID.ext.1

  • shellnew

Important considerations regarding file types include:

  • The HKEY_CLASSES_ROOT registry key 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 Key. 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 a file type entry in HKEY_CURRENT_USER\Software\Classes .
  • To ensure that an application is included in the Open With dialog box for a file type, include a reference to the application in either the OpenWithProgids or OpenWithList key for the file type.
  • 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, the change might not be recognized until the system is rebooted.
  • To retrieve information regarding a file association from the registry, use the IQueryAssociations interface.

Defining File Type Attributes

Assigning file type attributes to an associated ProgID enables you to control some aspects of the file type's behavior. These attributes also enable you to limit the extent to which the user can 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 values in the file type's associated ProgID key. To assign attributes for a file class, add an EditFlags REG_DWORD value to the file type's associated ProgID key and set it to the desired attribute value. The flags may be combined with a logical OR to form a single attribute value.

The following table lists the file class attributes and their hexadecimal values.

Flag Value Description
FTA_Exclude 0x00000001 Exclude the file class.
FTA_Show 0x00000002 Show file classes, such as folders, that aren't associated with a file name extension.
FTA_HasExtension 0x00000004 The file class has a file name extension.
FTA_NoEdit 0x00000008 The registry entries associated with this file class cannot be edited. New entries cannot be added, and existing entries cannot be modified or deleted.
FTA_NoRemove 0x00000010 The registry entries associated with this file class cannot be deleted.
FTA_NoNewVerb 0x00000020 No new verbs can be added to the file class.
FTA_NoEditVerb 0x00000040 Canonical verbs such as open and print cannot be modified or deleted.
FTA_NoRemoveVerb 0x00000080 Canonical verbs such as open and print cannot be deleted.
FTA_NoEditDesc 0x00000100 The description of the file class cannot be modified or deleted.
FTA_NoEditIcon 0x00000200 The icon assigned to the file class cannot be modified or deleted.
FTA_NoEditDflt 0x00000400 The default verb cannot be modified.
FTA_NoEditVerbCmd 0x00000800 The commands associated with verbs cannot be modified.
FTA_NoEditVerbExe 0x00001000 Verbs cannot be modified or deleted.
FTA_NoDDE 0x00002000 The Dynamic Data Exchange (DDE)-related entries cannot be modified or deleted.
FTA_NoEditMIME 0x00008000 The content-type and default-extension entries cannot be modified or deleted.
FTA_OpenIsSafe 0x00010000 The file class's open verb can be safely invoked for downloaded files. Note that this flag may create a security risk, because downloaded files could contain malicious content. To reduce this risk, consider methods to scan downloaded files before opening.
FTA_AlwaysUnsafe 0x00020000 Do not allow the Never ask me check box to be enabled. The user can override this attribute through the File Type dialog box. This flag also affects ShellExecute, download dialog boxes, and any application making use of the AssocIsDangerous function.
FTA_AlwaysShowExt 0x00040000 Always show the file class's file name extension, even if the user has selected the Hide Extensions option.
FTA_NoRecentDocs 0x00100000 Don't add members of this file class to the Recent Documents folder.

The following example assigns the FTA_NoRemove (0x00000010) and FTA_NoNewVerb (0x00000020) attributes to the .myp file class.

HKEY_CLASSES_ROOT

  • .myp-file
  • ...
  • ApplicationVendor.MyProgram

Public vs. Private File Types

File types are considered public if applications from multiple vendors are likely to handle the file format. Public file types are also called popular file types, because these types are most popular with users; software vendors are likely to create applications that handle these file types. Public file types are also called contentious, because multiple applications might want to be associated with the file type. These applications are often in direct competition, which can cause file type conflicts. Most often, file types that fall into the public category are defined by standards bodies, or promoted by their defining organizations as interchange formats. These files are often exchanged between computers and users for diverse purposes. Most common media formats are in this category because they often 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.

Private, or proprietary file types typically have a format that is implemented and understood by only one application or vendor. Public file types are by their nature contentious, whereas private file types are typically not prone to conflicts between applications. Sometimes private file types end up being public file types, so you should be aware of issues involving public file types.

Note  Windows does not differentiate between public and private file types. This is a logical separation only.

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 Program... from a file's context menu, the Shell presents the Open With dialog box, which enables the user to specify the program is used to open the file. The following images show examples of the Open With dialog box.

Open With dialog box on Windows XP

Open With dialog box on Windows Vista

Applications that are listed in the Open With dialog box are registered as subkeys of HKEY_CLASSES_ROOT\Applications . By default, an application with a key in HKEY_CLASSES_ROOT\Applications is listed in the Open With dialog box for any file the user attempts to open, including file types which the application is not registered to handle.

Sometimes an application should not be used to open files types it is not registered to handle. To exclude an application from the Open With dialog box for files that the application is not registered to handle, add an empty REG_SZ value named NoOpenWith to the application's key.

For example, assume that MyProgram.exe is registered to handle .myp and .txt files. The following sample registry entry excludes MyProgram.exe from being listed in the Open With dialog box for any file type other than .myp or .txt.

HKEY_CLASSES_ROOT

Applications

  • MyProgram.exe