;Author: Jim Michaels , Stu (AfroUK) ;Abstract: macro to create a simplistic internet shortcut (.url) or regular ; program/help/document shortcut (.lnk) with working directory. ;Version: 1.2 ;Creation Date: 4/18/2011 ;Current Date: 4/18/2011 ;credit for using Push and Pop for $OUTDIR and using SetOutPath to set the working dir goes to Stu. ;credit for counter idea comes from logiclib.nsh By dselkirk@hotmail.com and eccles@users.sf.net with IfNot support added by Message ;shortcut - macro that makes a basic shortcut with a working directory or an internet shortcut with no working directory. ;usage: !insertmacro shortcut urlORlnk filepathAppTitle targetAbsFilepathOrUrl workingDir ;example: ; !insertmacro shortcut 'url' '$SMPROGRAMS\$StartMenuFolder\site' 'http://JesusnJim.com/code/windows-dos/pwdgen.html' '' ; ${If} ${RunningX64} ; !insertmacro shortcut 'lnk' '$SMPROGRAMS\$StartMenuFolder\${PRODUCT_TITLE}' '$INSTDIR\64\pwdgengui64.exe' '$INSTDIR\64\' ; ${Else} ; !insertmacro shortcut 'lnk' '$SMPROGRAMS\$StartMenuFolder\${PRODUCT_TITLE}' '$INSTDIR\32\pwdgengui.exe' '$INSTDIR\32\' ; ${EndIf} ;instanceId must start with an alpha character and contain only digits, alphas and underscores. ;filepathtitle must not contain a file extension. you should put in a whole filepath. ;targetBaseFilepathNoExtOrUrl should be the entire filepath to the target executable or document, help file, etc if you specified 'lnk' as a shortcutType or a URL if you specified 'url' as the shortcutType. ;workingDir is the absolute path directory that the shortcut will consider the default directory. In windows XP, this is the shortcut's "Start In:" field. !ifndef _SHORTCUT_COUNTER_ !define _SHORTCUT_COUNTER_ 0 !macro shortcut urlORlnk filepathAppTitle targetAbsFilepathOrUrl workingDir ;handle like a switch statement the various shortcutType StrCmp ${urlORlnk} "url" __shortcut${_SHORTCUT_COUNTER_}url +1 StrCmp ${urlORlnk} "lnk" __shortcut${_SHORTCUT_COUNTER_}lnk +1 ;-----without the messagebox, this macro will silently fail if you feed shortcutType garbage. ;MsgBox MB_OK "The macro 'shortcut' had a problem: the author fed it the garbage '${shortcutType}'. Report the bug." Goto __shortcut${_SHORTCUT_COUNTER_}end __shortcut${_SHORTCUT_COUNTER_}url: WriteINIStr "${filepathAppTitle}.url" "InternetShortcut" "URL" "${targetAbsFilepathOrUrl}" Goto __shortcut${_SHORTCUT_COUNTER_}end __shortcut${_SHORTCUT_COUNTER_}lnk: Push $OUTDIR SetOutPath "${workingDir}" CreateShortCut "${filepathAppTitle}.lnk" "${targetAbsFilepathOrUrl}" Pop $OUTDIR Goto __shortcut${_SHORTCUT_COUNTER_}end __shortcut${_SHORTCUT_COUNTER_}end: !define __SHORTCUT_COUNTER_ ${_SHORTCUT_COUNTER_} !undef _SHORTCUT_COUNTER_ !define /math _SHORTCUT_COUNTER_ ${__SHORTCUT_COUNTER_} + 1 !undef __SHORTCUT_COUNTER_ !macroend !endif