Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
414 views
in Technique[技术] by (71.8m points)

installation - How to register file types/extensions with a WiX installer?

I didn't find an explicit answer to this question in the WiX Documentation (or Google, for that matter). Of course I could just write the appropriate registry keys in HKCR, but it makes me feel dirty and I'd expect this to be a standard task which should have a nice default solution.

For bonus points, I'd like to know how to make it "safe", i.e. don't overwrite existing registrations for the file type and remove the registration on uninstall only if it has been registered during installation and is unchanged.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Unfortunately there's no way to do a "safe" association with Windows Installer.

We just write everything out to the registry and then have a separate component that takes over the system-wide default and is only installed if no other application has already registered itself as the default.

With Vista there's the new "default programs" interface, again you write everything out to the registry. Here's a complete example that we're using in our installer. (WiX 3.0)

Update: 12 months have passed since my original answer and I have a better understanding of file associations. Rather than writing everything manually I'm now using proper ProgId definitions which improves handling for advertised packages. See the updated code posted in response to this question.

<Component ....>
    <RegistryValue Root="HKLM" Key="SOFTWAREAcmeFoobarCapabilities" Name="ApplicationDescription" Value="ACME Foobar XYZ Editor" Type="string" />
    <RegistryValue Root="HKLM" Key="SOFTWAREAcmeFoobarCapabilities" Name="ApplicationIcon" Value="[APPLICATIONFOLDER]AcmeFoobar.exe,0" Type="string" />
    <RegistryValue Root="HKLM" Key="SOFTWAREAcmeFoobarCapabilities" Name="ApplicationName" Value="ACME Foobar" Type="string" />
    <RegistryValue Root="HKLM" Key="SOFTWAREAcmeFoobarCapabilitiesDefaultIcon" Value="[APPLICATIONFOLDER]AcmeFoobar.exe,1" Type="string" />
    <RegistryValue Root="HKLM" Key="SOFTWAREAcmeFoobarCapabilitiesFileAssociations" Name=".xyz" Value="AcmeFoobar.Document" Type="string" />
    <RegistryValue Root="HKLM" Key="SOFTWAREAcmeFoobarCapabilitiesMIMEAssociations" Name="application/xyz" Value="AcmeFoobar.Document" Type="string" />
    <RegistryValue Root="HKLM" Key="SOFTWAREAcmeFoobarCapabilitiesshellOpencommand" Value="&quot;[APPLICATIONFOLDER]AcmeFoobar.exe&quot; &quot;%1&quot;" Type="string" />

    <RegistryValue Root="HKLM" Key="SOFTWARERegisteredApplications" Name="Acme Foobar" Value="SOFTWAREAcmeFoobarCapabilities" Type="string" />

    <RegistryValue Root="HKLM" Key="SOFTWAREClasses.xyz" Name="Content Type" Value="application/xyz" Type="string" />
    <RegistryValue Root="HKLM" Key="SOFTWAREClasses.xyzAcmeFoobar.DocumentShellNew" Value="" Type="string" />
    <RegistryValue Root="HKLM" Key="SOFTWAREClasses.xyzOpenWithListAcmeFoobar.exe" Value="" Type="string" />
    <RegistryValue Root="HKLM" Key="SOFTWAREClasses.xyzOpenWithProgids" Name="AcmeFoobar.Document" Value="" Type="string" />
    <RegistryValue Root="HKLM" Key="SOFTWAREClassesApplicationsAcmeFoobar.exeSupportedTypes" Name=".xyz" Value="" Type="string" />
    <RegistryValue Root="HKLM" Key="SOFTWAREClassesApplicationsAcmeFoobar.exeshellopen" Name="FriendlyAppName" Value="ACME Foobar" Type="string" />

    <RegistryValue Root="HKLM" Key="SOFTWAREMicrosoftWindowsCurrentVersionApp PathsAcmeFoobar.exe" Value="[!AcmeFoobar.exe]" Type="string" />
    <RegistryValue Root="HKLM" Key="SOFTWAREMicrosoftWindowsCurrentVersionApp PathsAcmeFoobar.exe" Name="Path" Value="[APPLICATIONFOLDER]" Type="string" />

    <RegistryValue Root="HKLM" Key="SOFTWAREClassesSystemFileAssociations.xyzshelledit.AcmeFoobar.exe" Value="Edit with ACME Foobar" Type="string" />
    <RegistryValue Root="HKLM" Key="SOFTWAREClassesSystemFileAssociations.xyzshelledit.AcmeFoobar.execommand" Value="&quot;[APPLICATIONFOLDER]AcmeFoobar.exe&quot; &quot;%1&quot;" Type="string" />

</Component>



<Component ....>
    <ProgId Id="AcmeFoobar.Document" Description="ACME XYZ Document">
        <Extension Id="pdf" ContentType="application/xyz">
            <Verb Id="open" Command="Open" TargetFile="[APPLICATIONFOLDER]AcmeFoobar.exe" Argument="%1" />
        </Extension>
    </ProgId>

    <Condition><![CDATA[DEFAULTVIEWER=1]]></Condition>
</Component>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...