Twain LogoScanners attached to client machines can be used from within a Citrix XenApp session via a mechanism called Twain Redirection.

For this mechanism to work correctly the file twain_32.dll must be present in the Windows directory.

On Windows 2008 this dll should be copied from winsxs (side by side) to the windows directory as described in CTX123981.

On Windows 2003 the dll is already in the correct directory, however applications that are not Terminal Server Aware cannot find this dll because the Windows directory is redirected to the user profile. Citrix recommends copying twain_32.dll to each user’s profile directory but this will take up unnecessary space.

So what alternatives do we have?

Method 1: Adjust DllCharacteristics field in the executable
The afore mentioned link on MSDN lists a procedure to set the TSAWARE flag when compiling (linking) an executable. But when can also set this property on binary (.exe) files.

There are various tools that can do this such as Microsoft’s editbin that comes with Visual Studio. In this example I will use NTCore’s CFF Explorer.

Start CFF Explorer and load the target executable, select Optional Header in the Treeview and change DllCharacteristics:

Change DllCharacteristics filed in the Optional Header

    Check the option “Terminal Server Aware” and click OK:

Set Terminal Server Aware Flag

Now save and test the executable.

Method 2: Set Terminal Server Application Compatibility Flag:
This method has the advantage that it doesn’t need a modification to the executable. It does have to be set per server but you could easily do this with a deployment tool or script.

Open regedit and create a key with the executable name (without extension) under “HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Terminal Server\Compatibility\Applications“.

In this key we need to set a Flags value for “Do not substitute user Windows directory” and “Windows 32-bit application”. The values are documented in Microsoft kb186499 as 0x00000400 and 0x00000008 which we need to “OR”.

So we create a DWORD named Flags and give the HEX value 408.

Or use the following reg file (don’t forget to change the executable name!):

With both methods the twain_32.dll will correctly load from the Windows directory!