title: NSIS - force user to select a different directory
body: <p>So far I've figured out how to detect a previous installation of my software by reading registry keys, and testing for whether the directory exists. (Both are well documented in the NSIS help file). Now I want to force the user to specify a different directory, if the application is previously installed. (Don't want to force uninstall by myself, because previous versions simply remove everything including saved data).</p>
  
  <p>As far as I can see, there are predefined templates in MUI2.nsh for the license, install folder, progress indicator etc. 
  How do I add a validation at this stage in the installer flow? </p>
  
  <p><strong>Update</strong> - Tried Paul's solution, but it doesn't work. 
  At the top of the script, I've declared</p>
  
  <pre><code>!define MUI_PAGE_CUSTOMFUNCTION_LEAVE validateDirectory
  !insertmacro MUI_PAGE_DIRECTORY
  </code></pre>
  
  <p>to refer to this function:</p>
  
  <pre><code>Function validateDirectory
  ReadRegStr $R0 HKLM "SOFTWARE\Aadhaar Enrolment Client" "Installdir"
  Pop $R0
  StrCmp $R0 $OUTDIR +1 +3
  MessageBox MB_ICONSTOP|MB_OK 'The directory $OUTDIR already exists.Please choose a different directory.'
  Abort
  FunctionEnd
  </code></pre>
  
  <p>This function displays the message, but doesn't abort. Moreover, if I click on 'back' in the directory selection page and again click forward, then it simply proceeds with the installation.</p>