Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Recommended PE header settings for Delphi 7 application running on terminal server?

Tags:

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.

The questions I've looked at include:

  • External exception C0000006
  • Delphi - invalid stream format errors on run
  • Are there risks associated with IMAGE_FILE_REMOVABLE_RUN_FROM_SWAP or IMAGE_FILE_NET_RUN_FROM_SWAP?
  • Delphi TOpenDialog hangs in windows 2008 when run as remote desktop application
  • Delphi 2007 : How to Set TSAWARE?
  • How can I force Delphi 7 to load the whole executable?

So far from reading these I'm thinking I should add the following to the .dpr file:

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}

Edit: Stripping the relocation section is probably unnecessary, so here's the revised version:

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}
like image 352
dougwoodrow Avatar asked Jan 17 '13 12:01

dougwoodrow


1 Answers

{$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}

is fine for your needs. I suspect that IMAGE_FILE_NET_RUN_FROM_SWAP is what you need to deal with C0000006. That error typically happens when you run from a network drive and the drive is not able to satisfy a page in request for the executable.

The other PE flags are fine for you either way. I would have it as you do.

As for whether or not IMAGE_DLLCHARACTERISTICS_TERMINAL_ SERVER_AWARE is right, only you know. Does you app meet the requiresments to be considered a non-legacy app for terminal services, as documented on MSDN? If so, use IMAGE_DLLCHARACTERISTICS_TERMINAL_ SERVER_AWARE.

like image 148
David Heffernan Avatar answered Sep 30 '22 06:09

David Heffernan