【问题标题】:How to create a multi-level subfolder in Start menu using WiX如何使用 WiX 在开始菜单中创建多级子文件夹
【发布时间】:2009-01-22 20:24:20
【问题描述】:

如何使用 WiX 在 Windows 开始菜单中创建子文件夹(深几级)?

目前我可以将快捷方式放在“开始”菜单中,但只能放在“程序”下的文件夹中(开始/程序/MyFolder),但我想更深地嵌套快捷方式(开始/程序/MyPlatform/MyProduct/等.)。我尝试了不同的组合,但是唉。

<DirectoryRef Id="StartMenuMyProduct">
    <Component Id="ApplicationShortcut" Guid="{PUT-SOME-GUID-HERE}">
        <Shortcut Id="ApplicationStartMenuShortcut"
                  Name="Configure My Product"
                  Description="Add or remove this and that"
                  Target="[MYPRODUCTDIR]ConfigureMyProduct.exe"
                  WorkingDirectory="MYPRODUCTDIR"/>
        <RemoveFolder Id="StartMenuMyProduct"
                      On="uninstall"/>
        <RemoveFolder Id="StartMenuMyPlatform"
                      On="uninstall"/>
        <RegistryValue Root="HKCU"
                       Key="SOFTWARE\MyCompany\MyPlatform\My Product"
                       Name="Installed"
                       Type="integer"
                       Value="1"
                       KeyPath="yes"/>
    </Component>
</DirectoryRef>

<!-- Shortcut to the configuration utility in the Windows Start menu -->
<Directory Id="ProgramMenuFolder">
    <!--<Directory Id="StartMenuMyPlatform" Name="MyPlatform">-->
      <Directory Id="StartMenuMyProduct" Name="My Product" />
    <!--</Directory>-->
</Directory>

【问题讨论】:

  • 好问题,没试过...
  • 顺便说一句,您的 GUID(如果您关心它保持“全球唯一 ID”;-),您不应该发布它)看起来是手工制作的。您应该只使用 Visual Studio 附带的 uuidgen.exe 或其他一些 guid 生成器。
  • 呵呵,谢谢,已更正。是的,我知道,我从我的源代码中复制并添加了一堆零,然后才发布到这里!

标签: installation wix windows-installer wix3


【解决方案1】:

有趣的是,MSI 要求创建一个注册表值来检测组件是否已安装。如果我们希望为所有快捷方式只创建一个这样的注册表值,那么我们必须将所有快捷方式放在一个组件中。

幸运的是,可以通过使用 Shortcut element 上的 Directory 属性来创建跨越多个目标目录的组件。

   <!-- shortcuts to applications in the start menu -->
   <DirectoryRef Id="ProgramMenuProductFolder">
      <Component Id="ProgramMenuShortcutsComponent" Guid="PUT-GUID-HERE">
         <!-- create folders -->
         <CreateFolder Directory="ProgramMenuVendorFolder" />
         <CreateFolder Directory="ProgramMenuProductFolder" />
         <CreateFolder Directory="ProgramMenuSubFolder" />
         <!-- remove folder -->
         <RemoveFolder Id="RemoveProgramMenuVendorFolder"
            Directory="ProgramMenuVendorFolder"
            On="uninstall" />
         <RemoveFolder Id="RemoveProgramMenuProductFolder"
            Directory="ProgramMenuProductFolder"
            On="uninstall" />
         <RemoveFolder Id="RemoveProgramMenuProductSubFolder"
            Directory="ProgramMenuProductSubFolder"
            On="uninstall" />
         <!-- main shortcut -->
         <Shortcut
            Id="MainShortcut"
            Name="My Product"
            Target="[SomeInstalledFolder]app1.exe" />
         <!-- shortcut in subfolder -->
         <Shortcut
            Id="SubFolderShortcut"             
            Name="mySubFolderShortcut"
            Target="[SomeInstalledFolder]app2.exe"
            Directory="ProgramMenuProductSubFolder" />
         <!--
            RegistryValue whichs serves as KeyPath
         -->
         <RegistryValue
            Root="HKCU"
            Key="Software\MyVendor\MyProduct"
            Name="InstalledStartMenuShortcuts"
            Type="integer"
            Value="1" />
      </Component>
   </DirectoryRef>

   <!-- shortcut directories -->
   <Directory Id="ProgramMenuFolder">
      <Directory Id="ProgramMenuVendorFolder" Name="MyVendor">
         <Directory Id="ProgramMenuProductFolder" Name="MyProduct">
            <Directory Id="ProgramMenuProductSubFolder" Name="MySubFolder" />
         </Directory>
      </Directory>
   </Directory>

【讨论】:

  • 小澄清,需要注册表值的不是 WiX,而是 MSI。我们只是按照蹩脚的要求生活。
  • 讨厌碰到这样一个旧线程,但我使用这个组件语法来创建我的快捷方式条目,当我使用主要升级安装较新版本时,它们没有得到正确清理,如下所示:blogs.technet.com/b/alexshev/archive/2008/02/15/…。所以我首先安装说 1.0.1.0,它将在开始菜单\程序\制造商\产品 1.0.1.0 中,如果我稍后安装 1.0.2.0,它将升级 1.0.1.0,但它会创建一个名为“开始菜单”的新条目程序\制造商\产品 1.0.2.0。如何让它正确清理?
  • 没关系,去掉产品快捷方式目录中的命名(现在称为开始菜单\程序\制造商\产品而不是开始菜单\程序\制造商\产品版本),现在似乎可以工作了。
  • 我对这篇旧帖子有一个问题:这些 CreateFolder 元素的目的是什么?因为在第二部分中,目录元素,文件夹结构已经定义,因此在安装过程中,如果这些目录不存在,将创建它们。那么那些 CreateFolder 的目的是什么?事实是我从来没有理解它。
  • @CandyChiu:我已经回滚了我上次的编辑,显然 CreateFolder 元素毕竟通常是必需的。请注意,我使用Directory= 属性来创建特定文件夹,而不是创建组件的父文件夹的默认行为。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2010-10-27
  • 1970-01-01
  • 1970-01-01
  • 2014-04-06
  • 1970-01-01
  • 2019-08-12
  • 1970-01-01
相关资源
最近更新 更多