Draco
Draco

Reputation: 16364

How can I set an icon for an asscociated file using WiX?

My application install file is being generated using WiX. In the WiX configuration I am associating a file type that works with the application. How can I associate an icon with this file type in the WiX configuration?

Upvotes: 8

Views: 9070

Answers (4)

Greg Dean
Greg Dean

Reputation: 30057

FROM: https://www.firegiant.com/wix/tutorial/getting-started/beyond-files/

If your application handles its own file data type, you will need to register a file association for it. Put a ProgId inside your component. FileId should refer to the Id attribute of the File element describing the file meant to handle the files of this extension. Note the exclamation mark: it will return the short path of the file instead of the long one:

<ProgId Id='AcmeFoobar.xyzfile' Description='Acme Foobar data file'>
  <Extension Id='xyz' ContentType='application/xyz'>
    <Verb Id='open' Sequence='10' Command='Open' Target='[!FileId]' Argument='"%1"' />
  </Extension>
</ProgId>

To assign an icon to this file type, you have to specify the appropriate registry entries yourself inside your component:

<Registry Id='FooIcon1' Root='HKCR' Key='.xyz' Action='write'
  Type='string' Value='AcmeFoobar.xyzfile' />
<Registry Id='FooIcon2' Root='HKCR' Key='AcmeFoobar.xyzfile' Action='write'
  Type='string' Value='Acme Foobar data file' />
<Registry Id='FooIcon3' Root='HKCR' Key='AcmeFoobar.xyzfile\DefaultIcon' Action='write'
  Type='string' Value='[INSTALLDIR]Foobar.exe,1' />

Upvotes: 10

adaem
adaem

Reputation: 9

Please note that Dracos answer is not suffiecent for a complete icon/file association.

The following code:

This is how I did it. I declared:

<Icon Id="Icon.exe" SourceFile="..\Installer\Graph.ico" /> 
<ProgId Id='myApp.exe' Description='Some description' Advertise='yes' Icon='Icon.exe'>
          <Extension Id='xyz' ContentType='application/text'>
            <Verb Id='open' Sequence='10' Command='Open' Argument='"%1"' />
          </Extension>
</ProgId>

Is only registering a file/icon association for the dialouges created by the application which is installed by the given wix-project. To get an icon that is shown overall for all the dialogues, desktop etc. in windows you also need to register your icon for a specific filetype (extension) in regedit.

Upvotes: -1

Blake Niemyjski
Blake Niemyjski

Reputation: 3577

I'd recommend following my stack overflow post located here for the simplest and most elegant way of embedding icons into a resource without the need for a c++ project in a managed .NET application.

Next, here is the proper way to set this via wix:

  <Component Id="stackoverflowFileRegistration" Guid="MY_GUID">

    <RegistryKey Root="HKCR" Key=".stackoverflow" ForceCreateOnInstall="yes" ForceDeleteOnUninstall="yes">
      <RegistryValue Value="stackoverflow.Document" Type="string" KeyPath="yes" />
      <RegistryValue Name="Content Type" Value="application/stackoverflow" Type="string" />
      <RegistryKey Key="ShellNew" ForceCreateOnInstall="yes" ForceDeleteOnUninstall="yes">
        <RegistryValue Name="NullFile" Value="" Type="string" />
        <RegistryValue Name="Data" Value="Default new document Content.. NOTE: you must use a MutiStringValue nodes for multi-line content...." Type="string"/>
      </RegistryKey>
    </RegistryKey>

    <RegistryKey Root="HKCR" Key="stackoverflow.Document" ForceCreateOnInstall="yes" ForceDeleteOnUninstall="yes">
      <RegistryValue Value="stackoverflow Document" Type="string" />

      <RegistryKey Key="DefaultIcon" ForceCreateOnInstall="yes" ForceDeleteOnUninstall="yes">
        <RegistryValue Value="[INSTALLDIR]bin\stackoverflow.lib.dll, 1" Type="string" />
      </RegistryKey>

      <RegistryKey Key="Shell" ForceCreateOnInstall="yes" ForceDeleteOnUninstall="yes">
        <RegistryKey Key="openstackoverflowwebsite" ForceCreateOnInstall="yes" ForceDeleteOnUninstall="yes">
          <RegistryValue Value="Open Stackoverflow" Type="string" />
          <RegistryKey Key="command" ForceCreateOnInstall="yes" ForceDeleteOnUninstall="yes">
            <RegistryValue Value="&quot;[INSTALLDIR]stackoverflow.exe&quot; /openwebsite &quot;%1&quot;" Type="string" />
          </RegistryKey>
        </RegistryKey>
      </RegistryKey>

    </RegistryKey>
  </Component>

This sample registers the default icon for a specific file extension (.stackoverflow) that is located in an assembly from step 1. It also shows how to create Windows Explorer associated right click commands as well as adds a menu item to the Windows Explorer New sub menu.

Thanks

-Blake Niemyjski

Upvotes: 0

Draco
Draco

Reputation: 16364

This is how I did it. I declared:

<Icon Id="Icon.exe" SourceFile="..\Installer\Graph.ico" />

before </Product> and added it as a reference as follows:

<ProgId Id='myApp.exe' Description='Some description' Advertise='yes' Icon='Icon.exe'>
          <Extension Id='xyz' ContentType='application/text'>
            <Verb Id='open' Sequence='10' Command='Open' Argument='"%1"' />
          </Extension>
</ProgId>

Upvotes: 7

Related Questions