使用 WiX 创建现有文件夹的桌面快捷方式

发布于 2024-08-29 19:13:49 字数 1247 浏览 8 评论 0原文

我需要使用 Wix 创建现有文件夹(而不是文件)的桌面快捷方式。更详细地说,我的安装程序有一个使用 C# 编写的与其关联的 CustomAction 程序。此 CustomAction 程序创建一个名为“BSS”的文件夹,其路径由用户选择。

C:\ProgramData\MT\BSS

现在我需要使用 WiX 将桌面快捷方式放置到此文件夹。但是,我遇到了一个问题,因为该文件夹在 WiX 中没有文件夹结构。我能找到的最接近的代码如下。

<Directory Id="DesktopFolder" Name="Desktop"/>
  <Directory Id="CommonAppDataFolder" Name="ProgramDataFolder"/>
  <Component Id="ComponentBSStrageShortcut" Guid="{8436995c-2e76-4030-b92d-c6b4bc243c43}">
    <Shortcut Id="ShortcutBSStrageShortcut"
              Directory="DesktopFolder"
              WorkingDirectory="APPLICATIONFOLDER"
              Target="[CommonAppDataFolder]/MTK/BSStrage"
              Name="BSStrage"
              Show="normal"/>
    <RegistryValue Action="write"
                   Key="SOFTWARE/MTK/BackStreet"
                   Root="HKCU"
                   Type="string"
                   KeyPath="yes"
                   Value="ApplicationFolderName"/>
  </Component>

当我以这种方式构建安装程序时,它实际上在桌面上创建了一个快捷方式。然而,WiX 似乎认为 BSStrage 是一个文件/应用程序,因此它在位置 C:\ProgramData\MT 中放置了一个名为 BSStrage 的虚构应用程序的快捷方式。但是双击它没有帮助,因为没有可以用来打开它的程序。

显然我在这里做错了。有人可以帮我解决这个问题,以便如何克服这个问题。请注意,我对 Wix 非常陌生(才两天),以前从未使用过它。任何代码示例都会有很大帮助。

I have the need to create a Desktop Shortcut to an existing FOLDER (NOT to a file) using Wix. To elaborate more, my installer program has a CustomAction program written using C# associated with it. This CustomAction program creates a folder named "BSS" of which the path is selected by user.

C:\ProgramData\MT\BSS

Now I need to place a Desktop Shortcut to this folder using WiX. However, I encounter a problem since this folder does not have a folder structure within WiX. The closest code I could find was the following.

<Directory Id="DesktopFolder" Name="Desktop"/>
  <Directory Id="CommonAppDataFolder" Name="ProgramDataFolder"/>
  <Component Id="ComponentBSStrageShortcut" Guid="{8436995c-2e76-4030-b92d-c6b4bc243c43}">
    <Shortcut Id="ShortcutBSStrageShortcut"
              Directory="DesktopFolder"
              WorkingDirectory="APPLICATIONFOLDER"
              Target="[CommonAppDataFolder]/MTK/BSStrage"
              Name="BSStrage"
              Show="normal"/>
    <RegistryValue Action="write"
                   Key="SOFTWARE/MTK/BackStreet"
                   Root="HKCU"
                   Type="string"
                   KeyPath="yes"
                   Value="ApplicationFolderName"/>
  </Component>

When I build the installer this way, it actually creates a shortcut on Desktop. However, WiX seems to think that BSStrage is a file/application so it places a shortcut to an imaginary application called BSStrage in the location C:\ProgramData\MT. But double clicking on it dosen't help as there is no program that can be used to open it.

Obviously I'm doing it wrong here. Can someone please help me with this, so as how to overcome this problem. Note that I'm extremely new to Wix (it's been only two days) and has never worked with it before. Any code sample would be of great help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

风柔一江水 2024-09-05 19:13:49

我刚刚遇到了同样的问题;似乎使用表单的 Target 属性创建 Shortcut 标记
Target="[CommonAppDataFolder]" 工作正常,但尝试附加子目录,例如
Target="[CommonAppDataFolder]\MTK\BSStrage" 导致创建的快捷方式不起作用。

幸运的是,我发现了一个解决方案。诀窍是创建一个 Directory 标记的层次结构,指向要创建快捷方式的目录,然后该目录包含一个 Component 标记,其中包含 Shortcut< /code> 标记,如下所示:

<Directory Id="DesktopFolder" Name="Desktop"/>
<Directory Id="CommonAppDataFolder" Name="ProgramDataFolder">
  <Directory Id="AppDataMTK" Name="MTK">
    <Directory Id="AppDataBSStrage" Name="BSStrage">
      <Component Id="ComponentBSStrageShortcut" Guid="{8436995c-2e76-4030-b92d-c6b4bc243c43}">
        <CreateFolder/>
        <Shortcut Id="ShortcutBSStrageShortcut"
                  Directory="DesktopFolder"
                  Name="BSStrage""/>
      </Component>
    </Directory>
  </Directory>
</Directory>

请注意,创建快捷方式时目标目录必须实际存在,否则您最终会遇到同样的问题:快捷方式损坏。这就是为什么我在 Component 标记内添加 标记,以在安装时创建目录。

I just ran into the same problem; it seems that creating a Shortcut tag with a Target attribute of the form
Target="[CommonAppDataFolder]" works fine, but trying to append subdirectories such as
Target="[CommonAppDataFolder]\MTK\BSStrage" results in the creation of a shortcut that doesn't work.

Fortunately, I've discovered a solution. The trick is to create a hierarchy of Directory tags leading to the directory that you want to create a shortcut to, which then contains a Component tag containing a Shortcut tag, like so:

<Directory Id="DesktopFolder" Name="Desktop"/>
<Directory Id="CommonAppDataFolder" Name="ProgramDataFolder">
  <Directory Id="AppDataMTK" Name="MTK">
    <Directory Id="AppDataBSStrage" Name="BSStrage">
      <Component Id="ComponentBSStrageShortcut" Guid="{8436995c-2e76-4030-b92d-c6b4bc243c43}">
        <CreateFolder/>
        <Shortcut Id="ShortcutBSStrageShortcut"
                  Directory="DesktopFolder"
                  Name="BSStrage""/>
      </Component>
    </Directory>
  </Directory>
</Directory>

Note that the target directory has to actually exist at the time the shortcut is created, or else you'll end up with the same problem: a broken shortcut. This is why I added the <CreateFolder/> tag inside the Component tag, to create the directory on install.

遮云壑 2024-09-05 19:13:49

Shortcut/@Target 中的斜杠应该是反斜杠。资源管理器可能会将您的快捷方式解释为“使用开关 /MTK 和 /BSStrage 启动 CommonAppDataFolder”。至少,这是我的第一个猜测。

The slashes in your Shortcut/@Target should be backslashes. Explorer is probably interpreting your shortcut as "Launch CommonAppDataFolder with switches /MTK and /BSStrage". At least, that's my first guess.

梦忆晨望 2024-09-05 19:13:49

我稍微改变了我的要求,并使代码按如下方式工作。改变的是现在我创建了 ProgramData 文件夹的快捷方式。

<!-- Desktop Shortcut --> 
  <Directory Id="DesktopFolder" Name="Desktop"/> 
  <Directory Id="CommonAppDataFolder" Name="ProgramDataFolder"/> 
  <Component Id="MTDesktopShortcut" Guid="{8436995c-2e76-4030-b92d-c6b4bc243c43}"> 
    <Shortcut Id="MTShortcut" 
              Directory="DesktopFolder" 
              WorkingDirectory="APPLICATIONFOLDER" 
              Target="[CommonAppDataFolder]" 
              Name="MT" 
              Show="normal"/> 
    <RegistryValue Action="write" 
                   Key="SOFTWARE/MT/BS" 
                   Root="HKCU" 
                   Type="string" 
                   KeyPath="yes" 
                   Value="ApplicationFolderName"/> 
  </Component> 

它工作正常并创建快捷方式。但是,存在一个问题,因为它在所有用户桌面上创建快捷方式,而我希望在当前用户的桌面上创建快捷方式。我应该做什么改变?

另请注意,我的安装程序执行所有用户安装,我无权更改它。我只需要一种在当前用户的桌面上创建此快捷方式的方法,而安装程序仍然可以进行所有用户安装。

I changed my requirements a bit and got the code to work as follows. Change being now I create a shortcut to the ProgramData folder.

<!-- Desktop Shortcut --> 
  <Directory Id="DesktopFolder" Name="Desktop"/> 
  <Directory Id="CommonAppDataFolder" Name="ProgramDataFolder"/> 
  <Component Id="MTDesktopShortcut" Guid="{8436995c-2e76-4030-b92d-c6b4bc243c43}"> 
    <Shortcut Id="MTShortcut" 
              Directory="DesktopFolder" 
              WorkingDirectory="APPLICATIONFOLDER" 
              Target="[CommonAppDataFolder]" 
              Name="MT" 
              Show="normal"/> 
    <RegistryValue Action="write" 
                   Key="SOFTWARE/MT/BS" 
                   Root="HKCU" 
                   Type="string" 
                   KeyPath="yes" 
                   Value="ApplicationFolderName"/> 
  </Component> 

It works fine and creates the shortcut fine. However there is one problem since it creates the shortcut on AllUsers Desktop while I want it to be created on the Current User's desktop. What change should I do?

Also note that my installer performs a all-user install, and I'm not at liberty to change that. I merely needs a way to create this shortcut on Current User's desktop while the installer can still do a all-user install.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文