Delphi and Terminal Server Aware

When an application is not Terminal Server aware (also known as a legacy application), Terminal Server makes certain modifications to the legacy application to make it work properly in a multiuser environment. For example, Terminal Server will create a virtual Windows folder, such that each user gets a Windows folder instead of getting the system’s Windows directory. This gives users access to their own INI files. In addition, Terminal Server makes some adjustments to the registry for a legacy application. These modifications slow the loading of the legacy application on Terminal Server and require up to 8 MegaBytes extra memory. This behaviour can be avoided if the TSAware flag is present in the PE header of an executable as can be read here at MSDN.

But how do we set this property in Delphi?

In Windows.pas we can see that the constant is defined:

But how to use this in your application?
Add the line

somewhere below the uses clause and we’re done!

Offcourse you are now responsible for making your application Terminal Server compliant which according to Microsoft means: If an application is Terminal Server aware, it must neither rely on INI files nor write to the HKEY_CURRENT_USER registry during setup.

Leave a Reply

  1. This flag works in Delphi7. I just tested it.
    How bad that I couldn’t find it in Delphi help although they implemented it.

    By the way: if it does not work move it behind the uses clause!! (I missed that, too)

  2. Maybe putting it in the .dpr would be even a better place (add windows unit to the uses clause)

  3. Can you point out why the application should not write to HKEY_CURRENT_USER during setup? It would clarify the situation.

  4. >>> [...] why the application should not write to HKEY_CURRENT_USER during setup <<<

    Having the TS Aware flag in an executable's header is a signal to Windows *not* to propagate HKCU settings that were written during setup (while the Terminal Server was in "Install Mode") to users at runtime (while in "Execute Mode"). Since this means that HKCU settings written during setup will only exist in the profile of the user who performed the installation, it would be "wrong" for the application to be expecting HKCU settings written during setup to be present for all users, so there's no point writing to HKCU during setup for such apps. The TS Aware flag should therefore only be used when the application has been written in such way that any default HKCU settings it may require will be written by the program itself (not the setup program) when a user launches it for the first time [such applications are referred to as "profile-aware"].

    For a fuller explanation of the ramifications of the TS Aware flag, see the following forum post:

    http://www.autohotkey.com/forum/topic16041.html

    I hope this helps.

    Jacques.