Old 1st November 2008, 03:40   #1
Red27
Junior Member
 
Join Date: Apr 2008
Posts: 6
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:

Quote:
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.
Red27 is offline   Reply With Quote
Old 1st November 2008, 12:58   #2
Kel Solaar
Junior Member
 
Join Date: Nov 2008
Posts: 2
I'm facing the same exact problem and would like to know what is the solution.

Here is my related section :
Quote:
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.

Quote:
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

Last edited by Kel Solaar; 1st November 2008 at 13:55.
Kel Solaar is offline   Reply With Quote
Old 1st November 2008, 14:40   #3
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
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
Afrow UK is offline   Reply With Quote
Old 1st November 2008, 14:52   #4
Kel Solaar
Junior Member
 
Join Date: Nov 2008
Posts: 2
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 ?
Kel Solaar is offline   Reply With Quote
Old 1st November 2008, 17:05   #5
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
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 is offline   Reply With Quote
Old 1st November 2008, 18:12   #6
Red27
Junior Member
 
Join Date: Apr 2008
Posts: 6
Afrow UK - brilliant - that 100% resolved the problem - thanks very much!
Red27 is offline   Reply With Quote
Old 2nd November 2008, 01:09   #7
LoRd_MuldeR
Major Dude
 
LoRd_MuldeR's Avatar
 
Join Date: Sep 2005
Location: Somewhere over the Slaughterhouse
Posts: 797
Instead of changing the OutPath two times, you could simply do:

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


My Plugins: StdUtils | NSISList | CPUFeatures | ExecTimeout | KillProc
My source of inspiration: http://youtu.be/lCwY4_0W1YI
LoRd_MuldeR is offline   Reply With Quote
Reply
Go Back   Winamp & Shoutcast Forums > Developer Center > NSIS Discussion

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump