cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Creating a File Association

Creating a File Association

Summary

In Windows-based applications, it is common to have some of the files that a setup installs to be opened with a specific program. For example, a setup author might want all .ved files to be opened with Windows Notepad. This article provides InstallScript code that creates an association between the .ved extension and Notepad in the registry.

Synopsis

In Windows-based applications, it is common to have some of the files that a setup installs to be opened with a specific program. For example, a setup author might want all .ved files to be opened with Windows Notepad. This article provides InstallScript code that creates an association between the .ved extension and Notepad in the registry.

Using the Explorer Shell, if you write the extension into the Extensions section of the Win.ini file, the information will be copied into the registry under the appropriate keys. Therefore, either modify the Win.ini file or the registry, but not both.

Note: Modifying the registry is easier under the Explorer shell since it is not necessary to define an application identification key. The \shell\open-print\command keys can be placed directly under the file extension key.

Applicable to Project Types:
Basic MSI
InstallScript
InstallScript MSI


Discussion

Attached below is a zip (Q100157.zip) that contains three script-based functions for creating and querying file associations in the registry on either the Explorer or Program Manager shells. To add to your setup, import these files into the <MYPROJECTDIR>\Script Files directory. Include the header file from the zip file (Q100157.zip) in the declarations block and the .rul file at the end of your script. You will then be able to call the functions anywhere in your script.


Additional Information

A file association can be created manually in the registry by following these steps:

To register a file extension you must do three things:

  1. Make a file extension key entry, such as:

    HKEY_CLASSES_ROOT\.zzz=zzzFile

  2. Make an application (class) identification key entry, such as:

    HKEY_CLASSES_ROOT\zzzFile=ZZZ File

  3. Make shell command key entries, such as the following:

    HKEY_CLASSES_ROOT\zzzFile\shell\open\command=Notepad.exe %1

    HKEY_CLASSES_ROOT\zzzFile\shell\print\command=Notepad.exe /P %1

    Follow the above instructions to register the .zzz file extension and associate Notepad with the .zzz file extension.

To accomplish the above steps, it is suggested to use the InstallScript functions RegDBCreateKey and/or RegDBSetKeyValueEx to create these registry entries. This is also shown in the sample code included in the attached .rul file.

To see example code that calls the necessary InstallScript registry-related functions to complete steps 1-3, see the InstallShield Help Library topic "Registering file extensions example code."

Note: All extension information is stored under HKEY_CLASSES_ROOT.

Additional information on the InstallScript functions mentioned above, including sample code, can be found in the self-titled topics contained in the InstallShield Help Library. For example, for additional information on using RegDBCreateKeyEx, please see the InstallShield Help Library topic RegDBCreateKeyEx.

Was this article helpful? Yes No
No ratings
Version history
Last update:
‎Oct 02, 2007 05:25 PM
Updated by: