NSIS Installation Restriction

I have an NSIS installer. I am working on the fact that I need to be able to prevent the installation of custom errors in folders (that is, $ SYSDIR, $ WINDIR, $ DESKTOP, etc.)

I want them to be able to choose the installation path, but just disable the next button if they choose the location indicated above. I searched everywhere and cannot find the answer to this question.

I tried to use this, but I can still install on the 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
+1
source share
1 answer

Use . onVerifyInstDir callback function.

Edit:

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

All Articles