我该如何在Wix安装项目中创建一个桌面快捷方式?
我该如何在Wix安装项目中创建一个桌面快捷方式?
这个快捷方式是一个非广告的快捷方式。记得将组件放在您的功能标签中。
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="DesktopFolder" Name="Desktop">
<Component Id="ApplicationShortcutDesktop" Guid="*">
<Shortcut Id="ApplicationDesktopShortcut"
Name="Text under your icon"
Description="Comment field in your shortcut"
Target="[MYAPPDIRPROPERTY]MyApp.exe"
WorkingDirectory="MYAPPDIRPROPERTY"/>
<RemoveFolder Id="DesktopFolder" On="uninstall"/>
<RegistryValue
Root="HKCU"
Key="Software\MyCompany\MyApplicationName"
Name="installed"
Type="integer"
Value="1"
KeyPath="yes"/>
</Component>
</Directory>
<Directory Id="ProgramFilesFolder" Name="PFiles">
<Directory Id="MyCompany" Name="MyCompany">
<Directory Id="MYAPPDIRPROPERTY" Name="MyAppName">
<!-- main installation files -->
</Directory>
</Directory>
</Directory>
</Directory>
Guid="*"
代替自动生成 GUID,��者使用 {PUT-GUID-HERE}。 - Stein Åsmul我认为我的方法更容易,您不需要创建注册表键:
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="DesktopFolder" SourceName="Desktop" />
<Directory Id="MergeRedirectFolder">
<Component Id="MyExeComponent" Guid="{PUT-GUID-HERE}">
<File Id="MyExeFile" Source="$(var.ExeSourcePath)" KeyPath="yes">
<Shortcut
Id="DesktopShortcut"
Directory="DesktopFolder"
Name="$(var.ShortcutName)"
WorkingDirectory="MergeRedirectFolder" />
</File>
</Component>
</Directory>
</Directory>
Directory_
字段引用特殊的DesktopFolder
文件夹,而Target
字段则携带值[#<ID-of-MyExeFile>]
。我唯一看到的缺点是文件和快捷方式都属于单个组件,因此不能单独安装它们。显然,安装快捷方式而不安装目标文件是没有意义的,但现在您也无法选择“在桌面上放置快捷方式”选项了。 - Armen Michaeli感谢提供示例。在 WIX 3.8 中仍然会出现以下错误:“Error 3 ICE43:组件...具有非广告快捷方式。它应该使用 HKCU 下的注册表键作为其 KeyPath,而不是文件。”
因此,在带有功能的文件中,我采用了以下方法:
<Component Id="cmp79F6D61F01DD1060F418A05609A6DA70"
Directory="dirBin" Guid="*">
<File Id="fil34B100315EFE9D878B5C2227CD1454E1" KeyPath="yes"
Source="$(var.SourceDir)\FARMS.exe" >
<Shortcut Id="DesktopShortcut"
Directory="DesktopFolder"
Name="FARMS $(var.FarmsVersion)"
Description="Local Land Services desktop application"
WorkingDirectory="INSTALLFOLDER"
Icon="FARMS.exe"
IconIndex="0"
Advertise="yes" >
<Icon Id="FARMS.exe" SourceFile="$(var.SourceDir)\FARMS.exe" />
</Shortcut>
</File>
</Component>
在产品定义文件中提到了桌面文件夹:
<Fragment>
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="DesktopFolder" Name="Desktop" />
<Directory Id="ProgramFilesFolder">
<Directory Id="INSTALLFOLDER" Name="FARMS" >
</Directory>
</Directory>
</Directory>
</Fragment>
<Fragment>
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="DesktopFolder" Name="Desktop"/>
那么,您应该为想要创建快捷方式的文件创建一个“快捷方式”组件。
<Component Id="PutYourComponentIdHere" Directory="FileDirectory" Guid="*">
<File Id="NotYourComponentId" KeyPath="yes" Source="..\YourFileSource\YourExecutable.exe">
<Shortcut Id="desktopServer" Directory="DesktopFolder" Name="YourShourtcutName" WorkingDirectory='WhereShouldYourShortcutPoint' Advertise="yes"/>
</File>
</Component>
这对我很有效。我需要放置图标,但这很容易。希望它能正常工作。
经过很多努力,我用了这种方式:
<Product ...>
<Feature Id="ProductFeature" Title="SetupProject" Level="1">
...
...
<ComponentRef Id="cmpDesktopShortcut" />
</Feature>
<Component Id="cmpDesktopShortcut" Guid="PUT-GUID-HERE" Directory="DesktopFolder" >
<Shortcut Id="MyDesktopShortcut"
Name="Setup Project"
Description="Opens the program."
Directory="DesktopFolder"
Target="[INSTALLFOLDER]App.exe"
WorkingDirectory="INSTALLFOLDER"/>
<RegistryValue Root="HKCU" Key="Software\My Company\Sample Application" Name="installed" Type="integer" Value="1" KeyPath="yes" />
</Component>
</Product>
我认为在多用户机器上,使用“当前用户”(HKCU)注册表键作为关键路径会导致问题。因为该注册表键仅为当前用户创建,当不同的用户登录时,安装的自动修复就会启动。