From MSI to WiX, Part 26 – Shortcut: To pin or not to pin?


As you may already know, Windows 7 supports setting properties on shortcuts and MSI 5.0 provides MsiShortcutProperty table to enable setting shortcut properties from installation package.


Let’s start with updated nonadvertised shortcut sample from Part 10:


<?xml version=1.0 encoding=UTF-8?>


 


<?define APPPATH = “D:\Learning\Wix\ShortcutProperty\ConsoleApp\bin\Debug”?>


 


<Wix xmlns=http://schemas.microsoft.com/wix/2006/wi>


  <Product Id=59226dd7-6c8a-41f4-900d-697967752465


           Name=ShortcutProperty


           Language=1033


           Version=1.0.0.0


           Manufacturer=ShortcutProperty


           UpgradeCode=256a8e92-2d80-4445-944c-6f3116b2f100>


    <Package InstallerVersion=200 Compressed=yes


             InstallScope=perMachine />


 


    <Media Id=1 Cabinet=media1.cab EmbedCab=yes />


 


    <Directory Id=TARGETDIR Name=SourceDir>


      <Directory Id=ProgramFilesFolder>


        <Directory Id=INSTALLLOCATION Name=ShortcutProperty>


 


          <Component Id=Component1


                     Guid={213F41E8-8AD5-4BEA-AFC5-652A02F6596F}


                     DiskId=1>


 


            <File Id=ConsoleApp.exe


                  Name=ConsoleApp.exe


                  Vital=yes


                  KeyPath=yes


                  Source=$(var.APPPATH)\ConsoleApp.exe />


 


          </Component>


 


 


          <Component Id=Component2


                     Guid={7D96A205-F60A-4bd2-AB66-9ADDFD49ED56}


                     DiskId=1>


 


            <RegistryValue Root=HKCU


                           Key=Software\ShortcutProperty\ConsoleApp


                           Name=installed


                           Type=integer


                           Value=1


                           KeyPath=yes/>


 


            <Shortcut Id=startmenuNonadv


                      Directory=ProgramMenuDir


                      Advertise=no


                      Name=ConsoleApp


                      WorkingDirectory=INSTALLDIR


                      Icon=Icon.exe


                      Target=[!ConsoleApp.exe]>


 


              <Icon Id=Icon.exe SourceFile=$(var.APPPATH)\ConsoleApp.exe />


 


            </Shortcut>


 


            <RemoveFolder Id=DeleteShortcutFolder


                          Directory=ProgramMenuDir


                          On=uninstall />


 


          </Component>


   


          </Directory>


      </Directory>


 


      <Directory Id=ProgramMenuFolder Name=Programs>


        <Directory Id=ProgramMenuDir Name=ConsoleApp ShortcutProperty sample />


      </Directory>


 


    </Directory>


 


    <Feature Id=ProductFeature Title=ShortcutProperty Level=1>


      <ComponentRef Id=Component1 />


      <ComponentRef Id=Component2 />


    </Feature>


  </Product>


</Wix>



After installing this application on Windows 7 you will notice that “ConsoleApp ShortcutProperty sample” menu in “All Programs” is highlighted (indicating that new program is installed) and if you will right-click on “ConsoleApp” shortcut, you’ll see “Pin to Taskbar” and “Pin to Start Menu” in the popup menu.


For my application I don’t want users to be notified that new application has been installed and I don’t want users to be able to pin my application to Taskbar.  Here is what we need to add to our shortcut component (inside <Sortcut> element):


<ShortcutProperty Id=ShortcutProperty.ConsoleApp


                  Key=System.AppUserModel.PreventPinning


                  Value=1 />


<ShortcutProperty Id=ShortcutProperty.ConsoleApp


                  Key=System.AppUserModel.ExcludeFromShowInNewInstall


                  Value=1 />


 Sample project is attached.


 

ShortcutProperty.zip

Comments (1)

  1. Alexander says:

    I have created advertised shortcut with WIX but I see only "Pin to Start menu" menu item. How can I enable Taskbar pinning support? Thanks.