Archive: CreateShortcut / Working Directory Problem


CreateShortcut / Working Directory Problem
Hi there,

I've having problems trying to amend the Working Directory to be the $INSTDIR for the Start Menu Shortcuts I create.

I'm using SetOutPath $INSTDIR successfully for the Desktop Shortcut I create ok, but for the Start Menu Short Cuts the Installer either:

a) fails to create the Shortcut (if I remove the SetOutPath command from the CREATE_SMGROUP_SHORTCUT macro, or change it to $INSTDIR), or

b) sets the working directory to be the Start Menu Group rather than the INSTDIR (if I leave the SetOutPath $SMPROGRAMS\$StartMenuGroup alone)

Here are the relevant sections of my script:

SetOutPath $INSTDIR
CreateShortcut "$DESKTOP\Program1.lnk" $INSTDIR\Program1.exe

!insertmacro CREATE_SMGROUP_SHORTCUT "Program 1" $INSTDIR\Program 1.exe
!insertmacro CREATE_SMGROUP_SHORTCUT "Program 2" $INSTDIR\Program 2.exe
!insertmacro CREATE_SMGROUP_SHORTCUT "Program 3" $INSTDIR\Program 3.exe

...

!macro CREATE_SMGROUP_SHORTCUT NAME PATH
Push "${NAME}"
Push "${PATH}"
Call CreateSMGroupShortcut
!macroend

...

Function CreateSMGroupShortcut
Exch $R0 ;PATH
Exch
Exch $R1 ;NAME
Push $R2
StrCpy $R2 $StartMenuGroup 1
StrCmp $R2 ">" no_smgroup
#SetOutPath $SMPROGRAMS\$StartMenuGroup *** SEEMS TO BE THE PROBLEM - BUT WHAT TO SET TO? ***
CreateShortcut "$SMPROGRAMS\$StartMenuGroup\$R1.lnk" $R0
no_smgroup:
Pop $R2
Pop $R1
Pop $R0
FunctionEnd
By the way, the macro was generated by the EclipseNSIS wizard.

I'd be grateful for suggestions.

Thanks.

I'm facing the same exact problem and would like to know what is the solution.

Here is my related section :

Section -post SEC0001
WriteRegStr HKLM "${REGKEY}" Path $INSTDIR
SetOutPath $INSTDIR
WriteUninstaller $INSTDIR\Uninstall.exe
!insertmacro MUI_STARTMENU_WRITE_BEGIN Application
SetOutPath $SMPROGRAMS\$StartMenuGroup
CreateShortcut "$SMPROGRAMS\$StartMenuGroup\$(^Name).lnk" $INSTDIR\$(^Name).exe
CreateShortcut "$SMPROGRAMS\$StartMenuGroup\Uninstall $(^Name).lnk" $INSTDIR\Uninstall.exe
!insertmacro MUI_STARTMENU_WRITE_END
WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$(^Name)" DisplayName "$(^Name)"
WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$(^Name)" DisplayVersion "${VERSION}"
WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$(^Name)" Publisher "${COMPANY}"
WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$(^Name)" URLInfoAbout "${URL}"
WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$(^Name)" DisplayIcon $INSTDIR\Uninstall.exe
WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$(^Name)" UninstallString $INSTDIR\Uninstall.exe
WriteRegDWORD HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$(^Name)" NoModify 1
WriteRegDWORD HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$(^Name)" NoRepair 1
SectionEnd
Edit : I found a workaround : copying the Desktop shortcut back to the Startup Menu, not really clean but it works. Hope someone will find a real solution.

SetOutPath $INSTDIR
CreateShortcut "$DESKTOP\$(^Name).lnk" $INSTDIR\$(^Name).exe
SetOutPath $SMPROGRAMS\$StartMenuGroup
CopyFiles "$DESKTOP\$(^Name).lnk" "$SMPROGRAMS\$StartMenuGroup\"
CreateShortcut "$SMPROGRAMS\$StartMenuGroup\Uninstall $(^Name).lnk" $INSTDIR\Uninstall.exe

Why not do:
SetOutPath $SMPROGRAMS\$StartMenuGroup
SetOutPath $INSTDIR
CreateShortcut "$SMPROGRAMS\$StartMenuGroup\$(^Name).lnk" $INSTDIR\$(^Name).exe
CreateShortcut "$SMPROGRAMS\$StartMenuGroup\Uninstall $(^Name).lnk" $INSTDIR\Uninstall.exe

Stu


It's working like a charm !

Btw I don't really understand the code tbh and why it's working

this alone :

SetOutPath $INSTDIR

don't work but this :

SetOutPath $SMPROGRAMS\$StartMenuGroup
SetOutPath $INSTDIR

is working, why ?


You need to create the directory before creating the shortcut in it. SetOutPath recursively creates the directories as well as sets the working directory to it.

Stu


Afrow UK - brilliant - that 100% resolved the problem - thanks very much! :D


Instead of changing the OutPath two times, you could simply do:

CreateDirectory $SMPROGRAMS\$StartMenuGroup
CreateShortcut "$SMPROGRAMS\$StartMenuGroup\$(^Name).lnk" $INSTDIR\$(^Name).exe
CreateShortcut "$SMPROGRAMS\$StartMenuGroup\Uninstall $(^Name).lnk" $INSTDIR\Uninstall.exe