Search code examples
nsis

SelectFolderDialog with only drives, no folder selection inside drives


In nsis SelectFolderDialog for folder selection window. But i want to appear or user to select only drives.There should not be selection of folders inside a drive. So user should get drives like C: D: E: etc Is there any option to do it?


Solution

  • This only allows you to select paths shorter than 4 characters inside My Computer, if you want to hide the folders in the dialog you need to write a plugin and implement IFolderFilter (WinXP+ only)

    #BIF_RETURNONLYFSDIRS 0x00000001
    #BIF_NEWDIALOGSTYLE 0x00000040
    #BIF_NONEWFOLDERBUTTON 0x00000200
    !include LogicLib.nsh
    !include WinMessages.nsh
    !define /math BFFM_ENABLEOK ${WM_USER} + 101
    !define BFFM_SELCHANGED 2
    System::Call 'SHELL32::SHGetSpecialFolderLocation(i0,i0x11,*i.r2)i.r0'
    System::Get "(i.R0,i.R1,i.R2,i)iR9R9"
    Pop $3
    System::Call '*(i$hwndparent,i$2,i,t "Hello",i0x241,kr3,i0,i0)i.r1'
    System::Call 'SHELL32::SHBrowseForFolder(ir1)i.r0'
    Sys_BFFCALLBACK:
        ${If} $R9 == "callback1"
            ${If} ${BFFM_SELCHANGED} = $R1
                System::Call 'SHELL32::SHGetPathFromIDList(i$R2,t "" R9)'
                StrLen $R9 $R9
                ${IfThen} $R9 > 3 ${|} StrCpy $R9 0 ${|}
                SendMessage $R0 ${BFFM_ENABLEOK} 0 $R9
            ${EndIf}
            StrCpy $R9 0 ; return value
            System::Call $3
            Goto Sys_BFFCALLBACK
        ${EndIf}
    System::Free $3 ; system callback
    System::Call 'OLE32::CoTaskMemFree(ir2)' ; BROWSEINFO.pidlRoot
    System::Free $1 ; BROWSEINFO
    ${If} $0 <> 0
        System::Call 'SHELL32::SHGetPathFromIDList(i$0,t "" R9)'
        MessageBox mb_ok SHBrowseForFolder=$R9
    ${EndIf}
    System::Call 'OLE32::CoTaskMemFree(ir0)' ; pidl result