![]() |
|
![]() |
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:
Since MAKEMSI doesn't know what the "target" will be, it obviously can't create components automatically for you!
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:
Windows installer required an "8.3" name, if you wish to supply a specific value then preceed the title with the 8.3 name followed by a "|", if this is not done then MAKEMSI will try to create one for you. If MAKEMSI creates the 8.3 name it may generate the same name for more than one long filename so if in doubt it is best to supply it.
The target of the shortcut is the keypath for the component this shortcut is a member of (see the "Component" parameter).
An advertised shortcut will repair the feature (and subfeatures) you have specified if required.
Some examples are:
A non-advertised shortcut should be a member of a component which has a current user registry keypath, the easiest way to do this is to specify "CU="Y"" on the "component" command.
Note that if a shortcut doesn't get created at all (no message) or you get a runtime error "1909" it is possible that the target field is not valid (ensure you supplied the full path to it).
You can use "{NL}" as a new line character.
For an advertised shortcut this component's keypath must be the required target!
If not supplied and not nested within a component then MAKEMSI will try to create the component for you, if it can't you will be told the reason.
The default for this parameter can be set via the DEFAULT_SHORTCUT_DIR macro. The default value is "[ProgramMenuFolder]". You can supply any number of directories seperated by ";" where each directory will create a shortcut in that location.
There are some standard folder keys which you can use, see Microsoft's MSI "System Folder Properties" for more information.
Icon aliases are defined with the "Icon" command. If the value is a known alias then we check if a file of that name exists (can be found). If a file exists an icon is created (via the "Icon" command) and the generated key used.
As you have less control over an automatically generated icon key you need to be aware of the "Icon Table keys longer than 57 bytes corrupt the Database" bug.
If the file is an ".ico" rather than ".exe" or ".dll" then you need to end the key in ".exe" for it to work...
Note that I do not know the effect of not specifying an icon... If you need to do this please let me know so I can update the doco...
If the "Icon" parameter was passed then the default is "0", else it is "".
"C" Headers will have a definition for "VK_F12" for the F12 key etc. I could not find the modifiers documented but a bit of experimentation showed that this is a bit mask with at least the following bits:
See below for an easy way of letting windows tell you what the correct value for any required key combination is. The value can be supplied as a decimal or hexadecimal value (for example "&H017B" where 01=Shift and 7B=F12 for Shift+F12).
The default for this parameter can be set via the DEFAULT_SHORTCUT_SHOWCMD macro. The default value is "ShowNormal".
The default for this parameter can be set via the DEFAULT_SHORTCUT_OPTIONS4COMPONENT macro. The initial value for this is "".
The default for this parameter can be set via the DEFAULT_SHORTCUT_DOCO macro. The initial value for this is "Y".
The default for this parameter can be set via the DEFAULT_SHORTCUT_DisplayResourceDLL macro.
The default for this parameter can be set via the DEFAULT_SHORTCUT_DisplayResourceId macro.
The default for this parameter can be set via the DEFAULT_SHORTCUT_DescriptionResourceDLL macro.
The default for this parameter can be set via the DEFAULT_SHORTCUT_DescriptionResourceId macro.
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>
![]() ![]() |
| ![]() ![]() |