title: Recommended PE header settings for Delphi 7 application running on terminal server?
body: <p>While investigating external exception C0000006 errors reported by some users running a Delphi 7 application on a Windows 2008 terminal server, I found several questions on this and related issues already.  I'm wondering if anyone has a definitive list of these settings that would be appropriate for a standard Delphi 7 database application running on a terminal server.</p>
  
  <p>The questions I've looked at include:</p>
  
  <ul>
  <li><a href="https://stackoverflow.com/questions/1317886/">External exception C0000006</a></li>
  <li><a href="https://stackoverflow.com/questions/13766310/">Delphi - invalid stream format errors on run</a></li>
  <li><a href="https://stackoverflow.com/questions/6953739/">Are there risks associated with IMAGE_FILE_REMOVABLE_RUN_FROM_SWAP or IMAGE_FILE_NET_RUN_FROM_SWAP?</a></li>
  <li><a href="https://stackoverflow.com/questions/3206010/">Delphi TOpenDialog hangs in windows 2008 when run as remote desktop application</a></li>
  <li><a href="https://stackoverflow.com/questions/13458485/">Delphi 2007 : How to Set TSAWARE?</a></li>
  <li><a href="https://stackoverflow.com/questions/12414509/">How can I force Delphi 7 to load the whole executable?</a></li>
  </ul>
  
  <p>So far from reading these I'm thinking I should add the following to the .dpr file:</p>
  
  <pre><code>const
    IMAGE_DLLCHARACTERISTICS_TERMINAL_SERVER_AWARE = $8000;
    // Following are already defined in D7's Windows.pas
    IMAGE_FILE_RELOCS_STRIPPED               = $0001;
    IMAGE_FILE_REMOVABLE_RUN_FROM_SWAP       = $0400;
    IMAGE_FILE_NET_RUN_FROM_SWAP             = $0800;
  
  {$SetPEOptFlags IMAGE_DLLCHARACTERISTICS_TERMINAL_SERVER_AWARE}
  
  {$SetPEFlags IMAGE_FILE_RELOCS_STRIPPED 
    or IMAGE_FILE_REMOVABLE_RUN_FROM_SWAP 
    or IMAGE_FILE_NET_RUN_FROM_SWAP}
  </code></pre>
  
  <p><strong>Edit:</strong> Stripping the relocation section is probably unnecessary, so here's the revised version:</p>
  
  <pre><code>const
    IMAGE_DLLCHARACTERISTICS_TERMINAL_SERVER_AWARE = $8000;
    // Following are already defined in D7's Windows.pas
    IMAGE_FILE_REMOVABLE_RUN_FROM_SWAP       = $0400;
    IMAGE_FILE_NET_RUN_FROM_SWAP             = $0800;
  
  {$SetPEOptFlags IMAGE_DLLCHARACTERISTICS_TERMINAL_SERVER_AWARE}
  
  {$SetPEFlags IMAGE_FILE_REMOVABLE_RUN_FROM_SWAP 
    or IMAGE_FILE_NET_RUN_FROM_SWAP}
  </code></pre>