首页 > 代码库 > WIX配置(二)-创建快捷方式
WIX配置(二)-创建快捷方式
创建开始菜单快捷方式
与上一节相同,需要先创建目录结构:
<Directory Id="ProgramMenuFolder">
<Directory Id="ApplicationProgramsFolder" Name="My Application Name"/>
</Directory>
第一个Directory的Id必须为"ProgramMenuFolder"(为windows安装程序指向开始菜单的属性值),该部分内容应该被放到id为TARGETDIR的目录中
为安装包添加快捷方式:
<DirectoryRef Id="ApplicationProgramsFolder">
<Component Id="ApplicationShortcut" Guid="4039b7c2-b789-48fe-b082-231215c34412">
<Shortcut Id="ApplicationStartMenuShortcut"
Name="MyApplication"
Description="My Application Description"
Target="[#WindowsFormsApplication.exe]"
WorkingDirectory="APPLICATIONROOTDIRECTORY"/>
<!--确保卸载时正确删除目录-->
<RemoveFolder Id="ApplicationProgramsFolder" On="uninstall"/>
<!--表示软件被安装-->
<RegistryValue Root="HKCU" Key="Software\Microsoft\MyApplication" Name="installed" Type="integer" Value="1" KeyPath="yes"/>
</Component>
</DirectoryRef>
需要告诉安装程序去创建快捷方式:
<ComponentRef Id="ApplicationShortcut" />
直接在Feature下添加
创建卸载开始菜单快捷方式
直接在上一步中DirectoryRef下添加一个卸载的Shortcut即可:
<Shortcut Id="UninstallProduct"
Name="Uninstall MyApplication"
Target="[System64Folder]msiexec.exe"
Arguments="/x [ProductCode]"
Description="Uninstalls My Application" />
添加桌面快捷方式
先添加一个目录,同样必须在Id为TARGETDIR的目录下
<Directory Id="DesktopFolder" Name="Desktop" />
为安装包添加快捷方式:
<DirectoryRef Id="DesktopFolder">
<Component Id="DesktopFolderShortcut" Guid="5A254682-DD1F-453D-8333-144457282026">
<Shortcut Id="DesktopShortcut" Directory="DesktopFolder" Name="myApplication" Target="[APPLICATIONROOTDIRECTORY]WindowsFormsApplication.exe" WorkingDirectory=" APPLICATIONROOTDIRECTORY " >
</Shortcut>
<RegistryValue Root="HKCU" Key="Software\Microsoft\MyApplication" Name="installed" Type="integer" Value="1" KeyPath="yes"/>
</Component>
</DirectoryRef>
完整的示例
<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Product Id="4039b7c2-b7be-48fe-b082-231215cb84a2" Name="SetupProject" Language="1033" Version="1.0.0.0" Manufacturer="man" UpgradeCode="4039b7c2-b7be-48fe-b082-231215cb8412">
<Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine" />
<MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." />
<MediaTemplate />
<Feature Id="ProductFeature" Title="SetupProject" Level="1">
<ComponentGroupRef Id="ProductComponents" />
<ComponentRef Id="ApplicationShortcut" />
<ComponentRef Id="DesktopFolderShortcut" />
</Feature>
</Product>
<Fragment>
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramFilesFolder">
<Directory Id="APPLICATIONROOTDIRECTORY" Name="MyApplication " />
</Directory>
<!--开始菜单中的目录-->
<Directory Id="ProgramMenuFolder">
<Directory Id="ApplicationProgramsFolder" Name="MyApplication"/>
</Directory>
<!--桌面目录-->
<Directory Id="DesktopFolder" Name="Desktop" />
</Directory>
<DirectoryRef Id="APPLICATIONROOTDIRECTORY">
<Component Id="WindowsFormsApplication.exe" Guid="4039b7c2-b7be-48fe-b082-231215c34412">
<File Id="WindowsFormsApplication.exe" Source="MySourceFiles\WindowsFormsApplication.exe" KeyPath="yes" Checksum="yes"/>
</Component>
<Directory Id="Files" Name="Files">
<Component Id="noimage1.jpg" Guid="4030b7c2-b7be-48fe-b282-231215cb8812">
<File Id="noimage1.jpg" Source="MySourceFiles\files\noimage1.jpg" KeyPath="yes"/>
</Component>
<Component Id="noimage.jpg" Guid="4030b7c2-b98e-48fe-b282-231215cb8412">
<File Id="noimage.jpg" Source="MySourceFiles\files\noimage.jpg" KeyPath="yes"/>
</Component>
</Directory>
</DirectoryRef>
<!--开始菜单快捷方式定义-->
<DirectoryRef Id="ApplicationProgramsFolder">
<Component Id="ApplicationShortcut" Guid="4039b7c2-b789-48fe-b082-231215c34412">
<Shortcut Id="ApplicationStartMenuShortcut"
Name="MyApplication"
Description="My Application Description"
Target="[#WindowsFormsApplication.exe]"
WorkingDirectory="APPLICATIONROOTDIRECTORY"/>
<!--卸载-->
<Shortcut Id="UninstallProduct"
Name="Uninstall MyApplication"
Target="[System64Folder]msiexec.exe"
Arguments="/x [ProductCode]"
Description="Uninstalls My Application" />
<!--确保卸载时正确删除目录-->
<RemoveFolder Id="ApplicationProgramsFolder" On="uninstall"/>
<!--表示软件被安装-->
<RegistryValue Root="HKCU" Key="Software\Microsoft\MyApplication" Name="installed" Type="integer" Value="1" KeyPath="yes"/>
</Component>
</DirectoryRef>
<!--桌面快捷方式-->
<DirectoryRef Id="DesktopFolder">
<Component Id="DesktopFolderShortcut" Guid="5A254682-DD1F-453D-8333-144457282026">
<Shortcut Id="DesktopShortcut" Directory="DesktopFolder" Name="myApplication" Target="[APPLICATIONROOTDIRECTORY]WindowsFormsApplication.exe" WorkingDirectory="APPLICATIONROOTDIRECTORY" >
</Shortcut>
<RegistryValue Root="HKCU" Key="Software\Microsoft\MyApplication" Name="installed" Type="integer" Value="1" KeyPath="yes"/>
</Component>
</DirectoryRef>
</Fragment>
<Fragment>
<ComponentGroup Id="ProductComponents" Directory="APPLICATIONROOTDIRECTORY">
<ComponentRef Id="WindowsFormsApplication.exe"/>
<ComponentRef Id="noimage1.jpg"/>
<ComponentRef Id="noimage.jpg"/>
</ComponentGroup>
</Fragment>
</Wix>
WIX配置(二)-创建快捷方式