Thứ Tư, 25 tháng 11, 2015

WiX - create Desktop shortcut and Start Menu shortcut

In this post, I will talk about creating Desktop shortcut and Start Menu shortcut.

1. Add componentRef's for Desktop shortcut and Start Menu shortcut

We need to add componentRef's for Desktop shortcut and Start Menu shortcut under Feature element.
In the Product.wxs file, find line of code that says:
 <Feature Id="ProductFeature" Title="AutoClick_FirstBlood" Level="1">
<ComponentGroupRef Id="ProductComponents" />
</Feature>
Replace it the following lines of code:
<Feature Id="ProductFeature" Title="AutoClick_FirstBlood" Level="1">
<ComponentGroupRef Id="ProductComponents" />
<ComponentRef Id="App_Desktop_Shortcut"/>
<ComponentRef Id="App_Start_Menu_Shortcut"/>
</Feature> 


2. Add directories of two folders using DesktopFolder and ProgramMenuFolder keywords.

In the Product.wxs file, find line of code that says:
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramFilesFolder">
<Directory Id="INSTALLFOLDER" Name="AutoClick_FirstBlood" />
</Directory>
</Directory>
Replace it with following lines of code:
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramFilesFolder">
<Directory Id="INSTALLFOLDER" Name="AutoClick_FirstBlood" />
</Directory>
<Directory Id="DesktopFolder" Name="Desktop"> </Directory>
<Directory Id="ProgramMenuFolder">
<Directory Id="ApplicationProgramsFolder" Name="AutoClick_FirstBlood" />
</Directory>
</Directory> 


3. Add shortcut component under directory reference.

In the Product.wxs file, add new some following lines of code:
<Fragment>
<DirectoryRef Id="DesktopFolder">
<Component Id="App_Desktop_Shortcut" Guid="327629B4-3339-432B-A574-6D9CB7DF8C8C">
<Shortcut Id="ApplicationDesktopShortcut"
Name="AutoClick_FirstBlood"
Target="[INSTALLFOLDER]AutoClick_FirstBlood.exe"
WorkingDirectory="INSTALLFOLDER" />
<RemoveFolder Id="RemoveDesktopFolder"
Directory="DesktopFolder"
On="uninstall" />
<RegistryValue Root="HKCU" Key="Software\AutoClick_FirstBlood"
Name="installed" Type="integer"
Value="1" KeyPath="yes" />
</Component>
</DirectoryRef>
<DirectoryRef Id="ApplicationProgramsFolder">
<Component Id="App_Start_Menu_Shortcut" Guid="0CAFCDBE-99AE-4656-BFE7-98FB02307D02">
<Shortcut Id="ApplicationStartMenuShortcut"
Name="AutoClick_FirstBlood"
Description="AutoClick_FirstBlood - an simple application about mouse events."
Target="[INSTALLFOLDER]AutoClick_FirstBlood.exe"
WorkingDirectory="INSTALLFOLDER" />
<RemoveFolder Id="RemoveApplicationProgramsFolder"
Directory="ApplicationProgramsFolder"
On="uninstall" />
<RegistryValue Root="HKCU" Key="Software\AutoClick_FirstBlood"
Name="installed" Type="integer"
Value="1" KeyPath="yes" />
   
</Component>
</DirectoryRef>
</Fragment>
Add shortcut components(Image 1)
Add shortcut components(Image 2)
**Note about Guid:
We need to generate a unique Guid for each Component.
A Guid has generated by Visual Studio as below:

  • Select ToolCreate GUID

  • Click New GUID, then click Copy


4. Rebuild the WiX project.

Previous    Next

Không có nhận xét nào:

Đăng nhận xét