Menu

#1084 CreateShortcut to folders fail when path referenced includes a "\.."

2.0 Series
open
nobody
None
5
2014-08-18
2013-11-08
No

Steps to reproduce

1 Place this in blah.nsi

!define PROJECT_NAME "blah"

OutFile "${PROJECT_NAME}.exe"
InstallDir "$PROGRAMFILES\${PROJECT_NAME}"

Section
   CreateDirectory "$SMPROGRAMS\${PROJECT_NAME}"
   CreateShortcut "$SMPROGRAMS\${PROJECT_NAME}\folder.lnk"  "$INSTDIR\..\"
SectionEnd

2 makensis blah.nsi
3 Run blah.exe
4 Start->All Programs->blah->folder

Expected results

A Windows Explorer window opened to the folder.

Actual results

A (broken) Windows shortcut. Instead am prompted with an "Open with" dialog since Windows seems to be confused what the shortcut is.

Right clicking on the shortcut actually shows that the shortcut Target type is File rather than expectedFile Folder

Additional details

mingw32-nsis-2.46-9.fc19.x86_64

Discussion

  • Anders

    Anders - 2013-11-08

    NSIS just calls IShellLink and does not change the path you give it in any way.

    It is a well known issue that when you create a shortcut the target has to exist before you create the shortcut because Windows tries to store as much information about the target as possible and sometimes it is too smart for its own good.

    When the target is a folder and it does not exist the final component in the PIDL gets stored as a SHDID_FS_FILE and not SHDID_FS_DIRECTORY. In this specific case the target does technically exist but Windows is not smart enough to figure this out. (If you run the example with "setup.exe /D=c:\foo" it would be broken no matter what since $instdir would not exist at all)

    The way around this is to make sure the target exists before creating the shortcut.

    If you absolutely need some relative path magic use:

    CreateDirectory $INSTDIR
    GetFullPathName $0 "$INSTDIR\.."
    CreateShortcut "$desktop\test.lnk" $0
    
     

    Last edit: Anders 2017-06-05
  • Leif Gruenwoldt

    Leif Gruenwoldt - 2013-12-06

    Thank you that workaround worked for me.

     

Log in to post a comment.