MAKEMSI quickly and reliably creates MSI files in a non-programmatic way
Have your say! Join the MAKEMSI discussion list or view archive! Suggest improvements. No question too simple or too complex.
[Bottom][Contents][Prev]: ServiceInstall[Next]: ShortcutUrl
Have your say! Join the MAKEMSI discussion list or view archive! Suggest improvements. No question too simple or too complex.
\->Source Code->Commands->Shortcut

The "Shortcut" Command

This command is used to create shortcuts to any applications however for internet shortcuts it is better to use the "ShortcutUrl" command. These types of shortcuts are supported:

  1. Advertised
    To create an advertised shortcut you pass a non-blank value for the "FEATURE" parameter and not use the "TARGET" parameter (the program to be "executed" is the file identified as the component keypath).

    Since MAKEMSI doesn't know what the "target" will be, it obviously can't create components automatically for you!

  2. Non-Advertised
    If you pass a non-blank value for the "TARGET" parameter but not the "FEATURE" parameter you wish to create a normal non-advertised shortcut.

  3. MAKEMSI Advertised Command Line
    If you pass a non-blank values for both the "TARGET" and "FEATURE" parameters then MAKEMSI does some "magic" which basically gives you the capabilities of an advertised shortcut but without some of the normal restrictions.

    To do this MAKEMSI creates some VBSCRIPT for you and adds it to the current component as the keypath (for this reason you can only have one shortcut per component).

    The generated VBSCRIPT will be able to execute the command line you supply via the "TARGET" and "ARGUMENTS" parameters! You need to be aware of the "Norton's Malicious Script Detection" issue.

    If the target is a file installed by this product then I'd recommend it be made the keypath of another component.

For a standalone example of how shortcuts are created have a look at the "TryMeShortcuts.MM" sample. This sample also shows how you could setup an uninstall shortcut.

Parameters

The command takes these parameters:

Main Shortcut Related Options

Please see the "options for commands" section of the manual.

#define? DEFAULT_SHORTCUT_DIR                      [ProgramMenuFolder]   ;;Default shortcut dir
#define? DEFAULT_SHORTCUT_ROWKEY_PREFIX            MmShortCut
#define? DEFAULT_SHORTCUT_PROPERTY_PREFIX          SHORTCUT              ;;Should be UPPER case
#define? DEFAULT_SHORTCUT_SHOWCMD                  SHOWNORMAL
#define? DEFAULT_SHORTCUT_DisplayResourceDLL
#define? DEFAULT_SHORTCUT_DisplayResourceId
#define? DEFAULT_SHORTCUT_DescriptionResourceDLL
#define? DEFAULT_SHORTCUT_DescriptionResourceId
#define? SHORTCUT_COMPONENT_AUTOCREATE_ALLOWED     Y                     ;;Y/N - Allowed to create components for you?
#define? SHORTCUT_COMPONENT_AUTOCREATE_INSTALLDIR                        ;;If blank MAKEMSI can't create its special advertised command line shortcuts
#define? SHORTCUT_COMPONENT_AUTOCREATE_KEYPATH     CU="Y"                ;;Create autocreated Component's keypath
#define? DEFAULT_SHORTCUT_OPTIONS4COMPONENT                              ;;Any options for autocreated components
#define? DEFAULT_SHORTCUT_DOCO                     Y                     ;;"N" = Don't add to doco (by default)
#define? SHORTCUT_COMPONENT_ROWKEY_REXXEXPRESSION  'AutoSC_' || {$RowKeyVar} ;;Key generated for autocreated components

An Easy Way to Determine a HotKey's Value

Windows allows you to set a hotkey for any shortcut by right clicking on one and opening its properties. Now a IE shortcut (URL) is a text file in the form of an INI file which means that this information is stored in a text format which can be viewed with any text editor!

So to work out the hotkey create an IE shortcut, right click and select properties, now enter the shortcut, press "apply". Open a command prompt and either type the shortcut file or load in a text editor (the file will have a ".URL" file extension), the following shows the shortcut, its properties windows as well as the shortcut opened in notepad:

EXAMPLE - ADVERTISED

This is an extract from the MAKEMSI MSI script which creates one of the documentation shortcuts:

<$cabinet "!">
    #(
       #define CHM
       The document is in Windows Compiled Help format and so
       has a contents, an index and can be searched.
    #)
    <$DirectoryTree Key="DOCODIR" Dir="[INSTALLDIR]\Documentation">
    <$Icon KEY="@Help" ".\help.ico">
    <$Component "ShortCutDocoMAKEMSI" Create="Y" Directory_="DOCODIR">
       <$DirectoryTree Key="SCDIR_DOCO" Dir="[SCDIR_MAKEMSI]\Documentation" Remove="Y">
       <$File Source="OUT\DOCO\MakeMsi\MakeMsi.chm" Comment='MAKEMSI documentation. <$CHM>' KeyPath="Y">
       #(
           <$Shortcut
                       Dir="SCDIR_DOCO"
                   Feature="."                             ;;Advertise current
                     Title="MAKEMSI's Documentation"
               Description="Documents the MAKEMSI tool (version <$ProductVersion>)."
                      Icon="@Help"
                   WorkDir="INSTALLDIR"

           >
       #)
    <$/Component>
<$/cabinet>

EXAMPLE - NOT ADVERTISED

<$DirectoryTree Key="INSTALLDIR"    Dir="c:\Program Files\SomeDir" CHANGE="\">
<$Icon KEY="@VersionInformationBox" ".\VersionInformationBox.ico">
<$Component "ShortCutFile" Create="Y" Directory_="INSTALLDIR">
    ;--- Add the file (make the component's keypath) ------------------------
    <$File RowKey="Target.vbs" Source="out\VersionInformationBox.vbs" Comment='Simple tool to display environmental version information.' KeyPath="Y">
<$/Component>
<$Component "ShortCutNonAdv" Create="Y" Directory_="INSTALLDIR" CU="Y">
   ;--- Create the shortcut (non-advertised) --------------------------------
   #(
       <$Shortcut
                   Dir="ProgramMenuFolder"
                Target="[!Target.vbs]"                  ;;"File" table key for file above
                 Title="Version|Display Versions"
           Description="Display Windows, WSH & Windows Installer version information."
                  Icon="@VersionInformationBox"
               WorkDir="INSTALLDIR"
       >
   #)
<$/Component>

EXAMPLE - SET TASKS PRIORITY

This example starts CSCRIPT so you'd expect the command window. If you didn't want it (non console application) then you wouldn't use the "/B" an "/Wait" switches (you might see a "flash" to eliminate this, start the program minimised).

<$Component "ShortcutsComponent" Create="Y" Directory_="INSTALLDIR" CU="Y">
    ;--- Run VBSCRIPT at a lower than normal priority -----------------------
    #(
       <$Shortcut
                   Dir="SOME_SHORTCUT_DIRECTORY"
                Target="[SystemFolder]CMD.EXE"
             Arguments=^/c START /B /Wait /BelowNormal cscript.exe //NoLogo "[INSTALLDIR]DoSomething.VBS" & pause^
                 Title="Do it!"
           Description="Go on try it."
               WorkDir="INSTALLDIR"
                  Icon="@DoSomething.ico"
       >
    #)
<$/Component>

EXAMPLE - OPEN EXPLORER IN FOLDER VIEW

<$Component "ShortcutsComponent" Create="Y" Directory_="INSTALLDIR" LM="Y">
    ;--- Create a Shortcut to the logging directory (key "LOG_DIR") ---------
    <$FileFind File="EXPLORER.EXE" Property="EXPLORER.EXE" PATH="[WindowsFolder]" Depth="0" Default="">
    #(
       <$Shortcut
                   Dir="SOME_SHORTCUT_DIRECTORY"
                Target="[EXPLORER.EXE]"
             Arguments=^/e,/root,[LOG_DIR]^
                 Title="Open Log Directory"
           Description="Open the log directory in folder view."
               WorkDir="INSTALLDIR"
                  Icon="@explorer.ico"
       >
    #)

    ;--- This is a per-machine install into an "all-users" location ---------
    <$MsiValFilter "Component ShortcutsComponent has non-advertised shortcuts. It's KeyPath registry key should fall under HKCU.">
    <$MsiValFilter "Component 'ShortcutsComponent' has both per-user and per-machine data with a per-machine KeyPath.">
<$/Component>

EXAMPLE - URL

If you want to create URL (web) shortcuts then I recommend you read the "URL Shortcuts" tip. Here is one way:

<$DirectoryTree Key="INSTALLDIR"    Dir="c:\Program Files\SomeDir" CHANGE="\">
<$Component "UrlShortcut" Create="Y" Directory_="INSTALLDIR" CU="Y">
   ;--- Create directory for shortcut ---
   <$DirectoryTree Key="INSTALLDIR_SC" Dir="[ProgramMenuFolder]\Shortcut Directory" MAKE="Y" REMOVE="Y">

   ;--- Add icon ---
   <$Icon Key="@Google" "test.ico">               ;;Key must end in ".exe" (WI feature)

   ;--- Create a shortcut ---
   #(
       <$Shortcut
                   Dir="INSTALLDIR_SC"
                Target="http://www.google.com/"
                 Title="DB$ - GOOGLE"
           Description="Go to google"
                  Icon="@Google"
             IconIndex="0"
       >
   #)
<$/Component>

EXAMPLES - NON-ADVERTISED SHORTCUTS WITH HKLM KEYPATH

The following code creates a component with a "local_machine" keypath, this will generate 2 warnings however as we ensure that the MSI is always installed per-machine we will override the expected messages:

;--- Create component with HKLM (not HKCU) Keypath --------------------------
<$Component "LogShortcuts" Create="Y" Directory_="LOGDIR" LM="Y">
   ;--- Filter out validation messages cause by the above HKLM keypath ------
   <$MsiValFilter "Component LogShortcuts has non-advertised shortcuts. It's KeyPath registry key should fall under HKCU.">
   <$MsiValFilter "Component 'LogShortcuts' has both per-user and per-machine data with a per-machine KeyPath.">

   ;--- Create the shortcuts ------------------------------------------------
   <$DirectoryTree Key="LOGMENUDIR"    Dir="[ProgramMenuFolder]\Tool Logs" MAKE="Y" REMOVE="Y">
   <$Icon KEY="ViewLog.ico.exe" ".\ViewLog.ico">
   #(
       ;--- Create macro for log file shortcuts (all look the same) ---------
       #define ToolLogSc
       <$Shortcut
                   Dir="LOGMENUDIR"
                TARGET="[SystemFolder]notepad.exe"   ;;Non-advertised
             Arguments=^"[LOGDIR]{$#1}"^
                 Title="View {$#1}"
           Description="View the log file ({$Desc})."
                  Icon="ViewLog.ico.exe"
               WorkDir="INSTALLDIR"
       >
   #)
   <$ToolLogSc "FirstLog.log"   Desc=^Hold information of type 1^>
   <$ToolLogSc "SecondLog.log"  Desc=^Hold information of type 2^>
   <$ToolLogSc "ThirdLog.log"   Desc=^More stuff^>
<$/Component>


Microsoft awarded me an MVP (Most Valuable Professional award) in 2004, 2005, 2006, 2007, 2008 & 2009 for the Windows SDK (Windows Installer) area.Please email me any feedback, additional information or corrections.
See this page online (look for updates)

[Top][Contents][Prev]: ServiceInstall[Next]: ShortcutUrl


MAKEMSI© is (C)opyright Dennis Bareis 2003-2008 (All rights reserved).
Saturday May 28 2022 at 3:11pm
Visit MAKEMSI's Home Page
Microsoft awarded me an MVP (Most Valuable Professional award) in 2004, 2005, 2006, 2007, 2008 & 2009 for the Windows SDK (Windows Installer) area.