【问题标题】:How to associate application with existing file types using WiX installer?如何使用 WiX 安装程序将应用程序与现有文件类型相关联?
【发布时间】:2010-05-05 10:43:03
【问题描述】:

与此相关:How to register file types/extensions with a WiX installer? 但不是重复的。

我需要处理现有的文件类型(.jpg 文件)。

我不希望我的应用成为 .jpg 的默认处理程序。我只想扩展“打开方式”菜单,并带有指向我的应用程序的链接。

我在注册表中看到了HKCR\.jpg\OpenWithList\HKCR\.jpg\OpenWithProgIds\,但我不确定是否要写入这些内容以及如何正确使用 WiX。我应该使用这样的东西吗?

<ProgId Id='??what here?' Description='Jpeg handled by my App'>
  <Extension Id='jpg' ContentType='image/jpeg'>
    <Verb Id='openwithmyapp' Sequence='10' Command='OpenWithMyApp' Target='[!FileId]' Argument='"%1"' />
  </Extension>
</ProgId>

这里有很多失败的方法(就像 Photo Mechanics 所做的那样,在我安装了这个软件之后,图像文件类型的 HKCR 真是一团糟)。

如何使用 WiX 正确执行此操作?

【问题讨论】:

  • 萨沙对链接问题的回答不提供这个吗?特别是,查看包括 OpenWith... 键在内的五个 RegistryValue。 (或者也许有一种更简洁的方法可以在 WiX 中指定它。)
  • 我对 Sasha 遗漏的正确方法很感兴趣 - 我想了解用于描述/内容类型等的值,如 e.g. ??这里是什么?在我的问题中。我还想了解哪些值是必需的,哪些不是,链接的答案似乎包含一些简单地提供文件处理程序可能不需要的东西。
  • 呃...我不久前写了那个答案。将尽快发布更清晰的代码。

标签: installation wix registry windows-installer file-type


【解决方案1】:

这是一个完整、完整的示例,其中的代码比链接的问题更详细、更简洁,应该能提供更好的答案。非常及时,因为我最近完成了之前发布的代码的移植,以使用正确的 ProgId 元素,所以这在我的脑海中是新鲜的;)

关于“这里有什么”,你几乎可以使用任何你喜欢的东西:)

<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="HKLM" Key="SOFTWARE\MyApp\Capabilities" Name="ApplicationDescription" Value="!(loc.ApplicationDescription)" Type="string" />
    <RegistryValue Root="HKLM" Key="SOFTWARE\MyApp\Capabilities" Name="ApplicationIcon" Value="[APPLICATIONFOLDER]MyApp.exe,0" Type="string" />
    <RegistryValue Root="HKLM" Key="SOFTWARE\MyApp\Capabilities" Name="ApplicationName" Value="!(loc.ApplicationName)" Type="string" />
    <RegistryValue Root="HKLM" Key="SOFTWARE\MyApp\Capabilities\DefaultIcon" Value="[APPLICATIONFOLDER]MyApp.exe,1" Type="string" />
    <RegistryValue Root="HKLM" Key="SOFTWARE\MyApp\Capabilities\FileAssociations" Name=".xyz" Value="MyApp.Document" Type="string" />
    <RegistryValue Root="HKLM" Key="SOFTWARE\MyApp\Capabilities\MIMEAssociations" Name="application/xyz" Value="MyApp.Document" Type="string" />
    <RegistryValue Root="HKLM" Key="SOFTWARE\MyApp\Capabilities\shell\Open\command" Value="&quot;[APPLICATIONFOLDER]MyApp.exe&quot; &quot;%1&quot;" Type="string" />
    <RegistryValue Root="HKLM" Key="SOFTWARE\RegisteredApplications" Name="MyApp" Value="SOFTWARE\MyApp\Capabilities" Type="string" />

    <!-- App Paths to support Start,Run -> "myapp" -->
    <RegistryValue Root="HKLM" Key="SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\MyApp.exe" Value="[!MyApp.exe]" Type="string" />
    <RegistryValue Root="HKLM" Key="SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\MyApp.exe" Name="Path" Value="[APPLICATIONFOLDER]" Type="string" />

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

    <!-- MyApp.Document ProgID -->
    <RegistryValue Root="HKLM" Key="SOFTWARE\Classes\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="HKLM" Key="SOFTWARE\Classes\SystemFileAssociations\.xyz\shell\edit.MyApp.exe" Value="!(loc.ExplorerMenuEditXYZ)" Type="string" />
    <RegistryValue Root="HKLM" Key="SOFTWARE\Classes\SystemFileAssociations\.xyz\shell\edit.MyApp.exe\command" Value="&quot;[APPLICATIONFOLDER]MyApp.exe&quot; &quot;%1&quot;" Type="string" />
</Component>

【讨论】:

  • 很酷的例子!您从哪里获得了所有这些注册表项所需的信息?你有 MSDN 文章的链接吗?
  • 这个例子,特别是在 ProgId 部分,看起来很像我的 WiX 代码,它接管了已经注册的文件扩展名。处理原始问题的技巧是什么,即防止 ProgId/Extension/Verb 元素接管现有的扩展?示例:我安装了一个处理 JPG 扩展名的程序。我不想让我的程序成为默认程序。我想要一个广告注册。我想参加“打开方式”。我有默认程序,注册打开方式等都想通了,但是如何防止强迫自己成为默认程序?
  • 在 Windows 8 中,问题会消失(终于!)对于较旧的操作系统,您将面临在不接管默认值的情况下进行广告注册的问题。您需要在单独的组件中未公布的注册表项,如果它们已经存在关联,则条件不会安装。我不再使用 Windows Installer,但几乎只是放弃了尝试干净地处理旧系统,因为底层的 Windows 逻辑似乎被破坏了。
  • 我知道这是一个旧答案,但使用此代码我似乎有一个区分大小写的问题。例如它适用于 TXT,但不适用于 txt。
  • 此解决方案是否仍然存在区分大小写的问题?
猜你喜欢
  • 1970-01-01
  • 2022-01-11
  • 2011-02-15
  • 2012-03-10
  • 2012-03-18
  • 1970-01-01
  • 2014-05-03
相关资源
最近更新 更多