Menu

#724 Dangerous example of MUI_STARTMENU_GETFOLDER macro

2.0 Series
closed-fixed
Modern UI (97)
5
2008-01-06
2008-01-05
No

NSIS version 2.34

The Modern UI 1/2 documentation contains a quite dangerous example of using the MUI_STARTMENU_GETFOLDER macro:

!insertmacro MUI_STARTMENU_GETFOLDER page_id $R0
Delete "$SMPROGRAMS\$R0\Your Shortcut.lnk"

People copy-pasting this can actually delete the whole start menu if "Do not create shortcuts" was chosen, because that will return the empty string in the uninstaller. I strongly suggest to replace the example with

!insertmacro MUI_STARTMENU_GETFOLDER page_id $R0
StrCmp $R0 "" NO_SHORTCUTS
Delete "$SMPROGRAMS\$R0\Your Shortcut.lnk"
NO_SHORTCUTS:

Thank you!

Discussion

  • Amir Szekely

    Amir Szekely - 2008-01-05
    • assigned_to: nobody --> joostverburg
     
  • Joost Verburg

    Joost Verburg - 2008-01-05

    Logged In: YES
    user_id=604457
    Originator: NO

    It doesn't really look dangerous to me.

    First of all the default folder will be returned if the registry value is empty. The default for this default folder is the installer name, which again can never be empty because NSIS also has a default for that. So $R0 should never be empty.

    And even if $R0 would be empty, the uninstaller would just attempt to remove "Your Shortcut.lnk" from the main Start Menu programs folder instead of the subfolder for the application. Delete also won't remove folders nor their content.

    Only when using commands like RMDir /r you should really be careful with possible empty variables. By the way, using RMDir /r in an uninstaller is usually not a good idea.

    Please clarify if I misunderstood your report.

     
  • Sebastian Pipping

    Logged In: YES
    user_id=1022691
    Originator: YES

    Well, the value returned was empty for NSIS 2.34 at my machine, I message-boxed it. I used RMDir /r on that folder. RMDir /r on a start menu folder should be fine since user don't put files in there.

    I opened this bug because I actually deleted a whole start menu this way by mistake.

     
  • Sebastian Pipping

    Logged In: YES
    user_id=1022691
    Originator: YES

    or to say it this way: if no shortcuts were created
    then executing

    !insertmacro MUI_STARTMENU_GETFOLDER page_id $R0
    Delete "$SMPROGRAMS\$R0\Your Shortcut.lnk"

    can only do damage.

     
  • Joost Verburg

    Joost Verburg - 2008-01-05

    Logged In: YES
    user_id=604457
    Originator: NO

    Can you provide a small script to reproduce this issue (the returned variable being empty)? I cannot reproduce it.

     
  • Sebastian Pipping

    Empty start menu folder variable bug demo

     
  • Sebastian Pipping

    Logged In: YES
    user_id=1022691
    Originator: YES

    Here is the requested demo script.
    Be sure to check "do not create shortcuts".

    NSIS version: 2.34
    System: Windows Server 2003 Enterprise SP2
    File Added: empty_start_menu_folder.nsi

     
  • Sebastian Pipping

    Logged In: YES
    user_id=1022691
    Originator: YES

    Addendum: I just noticed my example script was missing the line

    !define APP_START_MENU_PAGE_ID "StartMenuPage"

    so the page id is probably empty. I re-tried with that line but still the same.
    Are these macros expected to work with an empty page id?

     
  • Joost Verburg

    Joost Verburg - 2008-01-06

    Logged In: YES
    user_id=604457
    Originator: NO

    You're right, this is a bug in the Modern UI version 2.0. It works fine with Modern UI 1.x.

    The fix will be included in NSIS version 2.35. To solve it right now for your 2.34 version, replace Contrib\Modern UI
    2\Pages\StartMenu.nsh will the attached file.

    By the way, you don't need to check whether the variable that contains the Start Menu folder starts with ">". The MUI_STARTMENU_WRITE_BEGIN / MUI_STARTMENU_WRITE_END macros will verify that.
    File Added: StartMenu.nsh

     
  • Joost Verburg

    Joost Verburg - 2008-01-06
    • labels: 530426 --> Modern UI
    • status: open --> closed-fixed
     
  • Joost Verburg

    Joost Verburg - 2008-01-06
     
  • Sebastian Pipping

    Logged In: YES
    user_id=1022691
    Originator: YES

    I had a look at the new .nsh file. I am wondering if the variable is corrected to the default value then we end up deleting files that are not there. Should we instead delete no files at all? Is there a way for the uninstaller to find out whether start menu entries have been created or not? If not maybe we need another macro?

     
  • Joost Verburg

    Joost Verburg - 2008-01-06

    Logged In: YES
    user_id=604457
    Originator: NO

    The default Start Menu folder is the most likely location of the shortcuts, most users do not change it. If the registry value is somehow missing, it's not a bad guess to try to delete the shortcuts from the default location.

     

Log in to post a comment.