user1304228
user1304228

Reputation: 189

NSIS restrict folder installation

I have a NSIS installer I am working on that I need to be able to prevent installation to the "user error" folders (i.e. $SYSDIR, $WINDIR, $DESKTOP etc... )

I want them to be able to chose a installation path but just have the next button be disabled if they chose a location as listed above. I have searched everywhere and can't find an answer to this one.

I was trying to use this but I can still install to desktop:

!define MUI_PAGE_CUSTOMFUNCTION_LEAVE MyDirLeave
!insertmacro MUI_PAGE_DIRECTORY
...
Function MyDirLeave
  Push $0
    StrLen $0 $DESKTOP
    StrCpy $0 $INSTDIR $0
    StrCmp $0 $DESKTOP 0 proceed
    MessageBox MB_ICONSTOP|MB_OK \
        "Installation on DESKTOP is not allowed, choose another directory"
    Abort
    proceed:
  Pop $0
FunctionEnd

Upvotes: 2

Views: 2423

Answers (1)

Anders
Anders

Reputation: 101569

Use the .onVerifyInstDir callback function.

Edit:

Function .onVerifyInstDir
StrLen $0 $Desktop
StrCpy $0 $INSTDIR $0
StrCmp $0 $Desktop 0 PathGood
Abort
PathGood:
FunctionEnd

Upvotes: 4

Related Questions