title: How to notify Python from an Inno Setup that the environment path has changed?
body: <p>So I'm trying to create an installer that has the following steps:</p>
  
  <ol>
  <li>Check if Python is installed</li>
  <li>Copy my app files</li>
  <li>Check if the Python install directory is in the Windows Environment Path</li>
  <li>Check if the Python scripts folder is in the Windows Environment Path</li>
  <li><strong>If the scripts folder is not in the env path, add it</strong></li>
  <li><strong>install easy_install</strong></li>
  <li><strong>run a python script that uses easy_install to install several libraries</strong></li>
  </ol>
  
  <p>The problem is encountered in the last few steps. Here is the relevant code for the Inno setup I am currently using:</p>
  
  <pre><code>begin
    case CurStep of
       ssInstall:       // File transfer is about to begin.
       begin
          // Note: Use abort(); to terminate the install during this step.
       end;
  
  ssPostInstall:   // File transfer has finished.
    begin
       // Make sure Python is in the path.
       sPythonInstallDir := _PythonGetInstallDir();
       _PathAddToSystem( sPythonInstallDir )
       _PathAddToSystem( sPythonInstallDir + 'Scripts;' )
  
       // Run the bundled Python script.
       ExtractTemporaryFile( 'build_setup_script.py' );
       ExtractTemporaryFile( 'ez_setup.py'           );
       _LaunchApp( AddQuotes( sPythonInstallDir + 'python.exe' ), AddQuotes( ExpandConstant( '{tmp}\build_setup_script.py' ) ), ExpandConstant( '{tmp}' ), SW_SHOW, ewWaitUntilTerminated, 300, nTime, nResultCode );
    end;
  
  ssDone :         // After the Finish dialog.
    begin
    end;
  end;
  </code></pre>
  
  <p>here is the python script:</p>
  
  <pre><code>def main(argv):
     ## Easy Install
     print("Installing easy_install")
     call(["Python", "ez_setup.py"])
  ...
     ## Installs server.py dependencies
     print("\nInstalling SQLAlchemy")
     call(["easy_install", "SQLAlchemy==0.7.8"])
  ...
  </code></pre>
  
  <p>In the inno setup I also have the following directive</p>
  
  <pre><code>[Setup]
  ...
  ChangesEnvironment=true
  ...   
  </code></pre>
  
  <p>however, according to this <a href="https://stackoverflow.com/questions/12550791/innosetup-sendmessage-after-changing-the-environment-values">post</a>, the directive only takes effect after the user clicks finish.</p>
  
  <p>So the setup appends to the path:</p>
  
  <pre><code>...C:\Program Files (x86)\Git\cmd;;C:\Python27\;C:\Python27\Scripts;
  </code></pre>
  
  <p>but, then the script runs (which works because inno seems to be aware that the path has changed and can execute Python files) the script will then install easy_install, which works for some reason, but when it tries to use easy_install (which is why the C:Python\Scripts; is in the path) it throws a file not found exception. </p>
  
  <p>However, when I run the installer a second time, without making any changes, the easy_install steps will then work because now when Python runs, it can detect the path to easy_install.</p>
  
  <p>I figure there has to be a way to notify processes prior to clicking finish, however copying the code in the aforementioned <a href="https://stackoverflow.com/questions/12550791/innosetup-sendmessage-after-changing-the-environment-values">post</a> doesn't even compile in inno</p>
  
  <pre><code>SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, 0, LPARAM(PChar('Environment')), SMTO_ABORTIFHUNG, 5000, MsgResult);
  </code></pre>
  
  <p>Asking the user to start the install a second time is out of the question since the installer should be automated in the first place... any ideas?</p>