如何使用 WiX 安装程序注册文件类型/扩展名? [英] How to register file types/extensions with a WiX installer?

查看:24
本文介绍了如何使用 WiX 安装程序注册文件类型/扩展名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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.

解决方案

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>

这篇关于如何使用 WiX 安装程序注册文件类型/扩展名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆