5

Related to How to associate application with existing file types using WiX installer? and How to register file types/extensions with a WiX installer?.

How I can associate application with existing file types if the installation is per-user?

No HKLM key allowed

Community
  • 1
  • 1
Roberto
  • 504
  • 11
  • 23

2 Answers2

5

I believe this is not really different from the per-Machine case. For downmarker (which is installed per-User) I put this in the component which installs the application executable:

<!-- associate .md file extension with downmarker -->
<ProgId Id="DownMarker" Icon="downmarker.exe" 
    Description="Markdown Document">
    <Extension Id="md" >
       <Verb Id="open" Argument="&quot;%1&quot;"
          TargetFile="downmarker.exe" />
    </Extension>
</ProgId>

Or you can look at the full wxs file.

Wim Coenen
  • 66,094
  • 13
  • 157
  • 251
  • OK you are right. But what about all the nice things (like Vista/7 Capabilities, Open with, support for start run) that are described in the other threads? – Roberto Apr 19 '12 at 13:13
  • @Roberto: if those features normally work by putting registry entries in `HKLM`, and we assume that they are supported as per-User features as well, then logically my first attempt would be to put those registry entries under `HKCU` instead. You could even use `HKMU`, which wix will automatically resolve to `HKCU` or `HKLM` as appropriate. – Wim Coenen Apr 19 '12 at 13:40
  • @roberto: then I guess those features are not supported "per user". – Wim Coenen Apr 19 '12 at 17:01
  • Ok, I didn't understand why (probably I was doing something wrong) but now it is working – Roberto Apr 23 '12 at 10:40
3

Here we go.. this should work for per-user applications and give most of the nice stuff that you're looking for, except for start > run which is per-machine only.

<Icon Id="filetype.ico" SourceFile="filetype.ico" />
<Component Id="MyApp.exe" Directory="APPLICATIONFOLDER" Guid="*">
    <File Id="MyApp.exe" Name="MyApp.exe" KeyPath="yes"/>

    <Shortcut Id="startmenuShortcut" Directory="ProgramMenuFolder" Name="MyApp" Icon="$(var.product).ico" IconIndex="0" WorkingDirectory="APPLICATIONFOLDER" Advertise="yes" />

    <!-- Capabilities keys for Vista/7 "Set Program Access and Defaults" -->
    <RegistryValue Root="HKCU" Key="SOFTWARE\MyApp\Capabilities" Name="ApplicationDescription" Value="!(loc.ApplicationDescription)" Type="string" />
    <RegistryValue Root="HKCU" Key="SOFTWARE\MyApp\Capabilities" Name="ApplicationIcon" Value="[APPLICATIONFOLDER]MyApp.exe,0" Type="string" />
    <RegistryValue Root="HKCU" Key="SOFTWARE\MyApp\Capabilities" Name="ApplicationName" Value="!(loc.ApplicationName)" Type="string" />
    <RegistryValue Root="HKCU" Key="SOFTWARE\MyApp\Capabilities\DefaultIcon" Value="[APPLICATIONFOLDER]MyApp.exe,1" Type="string" />
    <RegistryValue Root="HKCU" Key="SOFTWARE\MyApp\Capabilities\FileAssociations" Name=".xyz" Value="MyApp.Document" Type="string" />
    <RegistryValue Root="HKCU" Key="SOFTWARE\MyApp\Capabilities\MIMEAssociations" Name="application/xyz" Value="MyApp.Document" Type="string" />
    <RegistryValue Root="HKCU" Key="SOFTWARE\MyApp\Capabilities\shell\Open\command" Value="&quot;[APPLICATIONFOLDER]MyApp.exe&quot; &quot;%1&quot;" Type="string" />
    <RegistryValue Root="HKCU" Key="SOFTWARE\RegisteredApplications" Name="MyApp" Value="SOFTWARE\MyApp\Capabilities" Type="string" />

    <!-- Extend to the "open with" list + Win7 jump menu pinning  -->
    <RegistryValue Root="HKCR" Key="Applications\MyApp.exe\SupportedTypes" Name=".xyz" Value="" Type="string" />
    <RegistryValue Root="HKCR" Key="Applications\MyApp.exe\shell\open" Name="FriendlyAppName" Value="!(loc.ApplicationName)" Type="string" />

    <!-- MyApp.Document ProgID -->
    <RegistryValue Root="HKCR" Key="MyApp.Document" Name="FriendlyTypeName" Value="!(loc.DescXYZ)" Type="string" />
    <ProgId Id="MyApp.Document" Description="!(loc.DescXYZ)" Icon="filetype.ico" Advertise="yes">
        <Extension Id="xyz">
            <Verb Id="open" Command="!(loc.ExplorerMenuOpenXYZ)" Argument="&quot;%1&quot;" />
            <MIME Advertise="yes" ContentType="application/xyz" Default="yes" />
        </Extension>
    </ProgId>

    <!-- Optional: add an 'Edit with XYZ' to 'right click' even when not associated -->
    <RegistryValue Root="HKCR" Key="SystemFileAssociations\.xyz\shell\edit.MyApp.exe" Value="!(loc.ExplorerMenuEditXYZ)" Type="string" />
    <RegistryValue Root="HKCR" Key="SystemFileAssociations\.xyz\shell\edit.MyApp.exe\command" Value="&quot;[APPLICATIONFOLDER]MyApp.exe&quot; &quot;%1&quot;" Type="string" />
</Component>
saschabeaumont
  • 22,080
  • 4
  • 63
  • 85