CITRIX – Scanner TWAIN troubleshooting

Here are a few steps which I followed to troubleshoot scanning issues in my environment. Citrix recommends having TWAIN drivers in the user profile and Windows root directory but sometimes it’s not that simple, to troubleshoot we need to dig deeper to understand the Citrix scanning model.

TWAIN Scanning Requirements

  • The scanner must be TWAIN compliant.
  • Install the TWAIN drivers on the local device. They are not required on the server.
  • Attach the scanner locally (for example, through USB).
  • Ensure that the scanner is using the local TWAIN driver and not the Windows Image Acquisition service.
  • Ensure that there is no policy applied to the user account that is used for the test, and which is limiting the bandwidth within the ICA session. For example, client USB redirection bandwidth limit.

TWAIN redirection explained


When the user picks “Select Source”, the request is processed using the following steps:

  1. The application sends a Twain command to the twain_32.dll module, which is a part of Windows. However, this command is intercepted by the Twain Redirector module which replaces (leveraging MfApHook) the standard twain_32.dll module.
  2. The Redirector sends the request to a Twain Multiplexer which runs inside of WFShell.
  3. The Multiplexer forwards the request to the ICA client using a new virtual channel.
  4. The client-side virtual channel driver, also known as the Twain De-multiplexer, forwards the request to a Twain Proxy application. There is a separate proxy application for each imaging application that runs on the server.
  5. The proxy application makes the actual call to the client-side twain_32.dll module.
  6. Return information is sent using the reverse of these steps.


The TWAIN virtual channel is responsible for establishing the endpoints between the client and the session and TWAIN specific commands are sent back and forth between the two ends. The following components implement the Twain redirection feature:

On the server

1.   The TWNRDR.dll (TWAIN Redirector) hook DLL gets loaded inside an application, hooks calls of interest from an application and redirects them to the TwnMux virtual channel over a named pipe communication channel. The TwnMux virtual channel is responsible for forwarding the data to the client.

2.   The TwnMux.dll (TWAIN multiplexor) hosts the virtual channel endpoint inside the wfshell.exe process and is responsible for communicating with the client endpoint.

On the Client

1.   The vdtwn.dll (TWAIN virtual driver) hosts the virtual channel endpoint inside the ICA Client engine. It establishes the communication channel with the server virtual channel endpoint. It receives/forwards data/requests to the proxy application that runs in the context of the user on the client using a custom IPC mechanism.

2.   CtxTwnPa.exe (TWAIN proxy app) is the proxy application that runs in the context of the user.

The solution which worked:

WIA service was in a disabled state. Twain redirection policy not enabled. As per
“TWAIN redirection fails on hosted shared desktops and applications. This is a third party issue related to TWAIN applications that require TWAIN binaries to be located in certain paths. [#300854, 340999]

As a workaround, on your Windows Server 2012 machine running the VDA, copy these files to the following locations:

  • Copy “twain_32.dll” to the “\WINDOWS” directory of the User profile (for example, copy twain_32.dll into the folder: “%USERPROFILE%\Windows\”).
  • Copy “twain_32.dll.mui” into the “\WINDOWS\en-US\” directory of the User profile (for example, copy twain_32.dll.mui into the folder: “%USERPROFILE%\Windows\en-US\”).You can copy en-US directory directly from C:\windows\en-US

 How to configure to use the scanner (TWAIN) with ICA


Citrix policies must be enabled (depending on the type of scanner).

User-added image

Other requirements

·         The scanner must be TWAIN compliant

·         The TWAIN drivers must be installed on the local device.  They do not need to be installed on the XenApp server

·         The scanner must be attached locally (through USB, for example)

·         Ensure that the scanner is using the local TWAIN driver and not the Windows Image Acquisition service

·         Ensure that there is no policy applied to the user account used for the test that is limiting the bandwidth within the ICA session (client USB redirection bandwidth limit for example)

·         After the Desktop Experience feature is installed, click Close to exit the Add Features Wizard, and then click yes to restart the computer

Symptoms or Error

Scanner not recognized when ‘optimized’ virtual channel is used. Below articles were already implemented to configure Generic USB redirection:


Configured the automatic Generic USB redirection of TWAIN device with the below steps:

>Verify on the client below is enabled:

32 bit OS:

“AutoRedirectImage”=dword: 1  (Decimal)

64 bit OS:

[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432 Node\Citrix\ICA Client\GenericUSB\Devices]
“AutoRedirectImage”=dword: 1  (Decimal)

> In the Studio, configure the existing or create a new policy TWAIN Devices > Client TWAIN device redirection > ( Set to Prohibited)
Default is Allowed . This would stop virtual channel redirection for TWAIN device only.

>To configure automatic redirection navigate to HKLM\Software\Wow6432Node\Citrix\ICA Client

Create a new Key: “USB”. Inside USB, create the following entries:

ExistingDevices (REG_SZ) = Always
NewDevices (REG_SZ) = Always
ShowAllDevices (REG_DWORD) = 1

>If these steps don’t help either then on existing configuration edit the policy and configure the below changes at user configuration:

User-added image

How to Troubleshoot TWAIN Redirection Functionality with XenApp


TWAIN troubleshooting can be divided into the following two sections:

Section 1 – Acquiring the scanner through an ICA session

  1. Ensure that the server edition is set to Advanced or higher.
  2. Ensure that the server version is set to 4.0 or higher.
  3. Ensure that a version 9.0 or later ICA client is used. Upgrade to the latest ICA client or test downgrading the client to isolate client-side issues.
  4. Test your scanner and application locally by disabling the Windows Image Acquisition (WIA) service. This ensures that only TWAIN is being used for image acquisition.
  5. Perform the same test from step 4 on the server console to verify that you can acquire images successfully on the console.
    Note: A TWAIN-enabled application must be installed on the server to use this feature.
  1. On the ICA client device, ensure the following two files are installed:
  • Program Files\Citrix\ICA Client\VDTWN.dll
  • Program Files\Citrix\ICA Client\CtxTwnPA.exe
  1. When you launch the TWAIN compliant application on the server (through an ICA session), use Filemon or task manager to verify CtxTwnPA.exe is being launched on the client workstation when trying to acquire a scanner from the published application. This helps determine if the TWAIN calls are being redirected to the client.
  2. For TWAIN redirection, some applications are not Terminal Services aware and look for Twain_32.dll in the \WINDOWS directory of the user profile (by default, C:\Documents and Settings\UserName\Windows). Copying Twain_32.dll into the \Windows directory of each user profile resolves this issue.
  3. Use Filemon to verify the application is finding Twain_32.dll and the folder in which it is trying to access.
  4. In some instances, the problem can be corrected by adding the application to the Terminal Services application compatibility list with the following two flags specified (see Microsoft Knowledge Base Article 186499 for more information):
  • Windows 32-bit application: 0x00000008
  • Do not substitute user Windows directory: 0x00000400
  1. To automate the process of enabling these flags on the server, copy the following text to a text editor and save it as a .reg file. [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Terminal Server\Compatibility\Applications\Photoshop] “Flags”=dword:00000408
    Note: You might need to combine these flags with other compatibility flags needed for the application.

This feature supports the following modes of TWAIN information transfer:

  • Native
  • Buffered Memory (most scanning software works by default in Buffered Memory mode).


  • The Disk File transfer mode is not supported.
  • An ICA session from a Win16 or WinCE device (HPC and WBT) does not currently support TWAIN redirection.  For additional information on TWAIN redirection support with various non-Windows clients, refer to the client feature matrix at

Section 2 – Acquiring the image through the scanning process

After ensuring the scanner availability through preceding processes, complete the following steps for proper image acquisition through an ICA session.

  1. Verify if the issue is application-specific. Does the issue occur only for a custom application or all the applications on the server? The Microsoft Image Scanning utility is a useful tool for verifying the image acquisition process.
  2. Change different settings of the image, such as color versus grayscale to see if the image acquisition completes successfully.
  3. Known Issue: When using TWAIN redirection, third-party published scanning applications might unexpectedly exit while receiving scan data from the client. This issue is limited to scanning in grayscale mode.
    Refer to CTX108555 – Hotfix PSE400R01W2k3013 – For Citrix Presentation Server 4.0 for Windows Server 2003 and CTX109090 – Hotfix PSE400R01W2K023 – For Citrix Presentation Server 4.0 for Windows 2000 Server for more information.
  1. If this issue is occurring only with a third-party or custom application, obtain input from the application vendor to determine the process taken to acquire images with TWAIN.

Testing Scanning Tools.

You can use the following tools by publishing these Apps to verify TWAIN driver’s redirection and scanning.

  • Demo Dynamsoft :
  • NAPS2 :
  • PROCMON: Microsoft Process Monitor to verify the right processes are loading :
  • TWAIN Data Source Library :

TWAIN testing tool

Install Twacker – a third party TWAIN testing tool – to the XenApp server and to the local client device to test TWAIN scanning within a XenApp desktop session.

Download from here.

  1. Install Twacker.
  2. Within a XenApp published desktop session:
  1. Launch Twacker (32 bit version).
  2. Click File > Select Source and select your scanner from the list.
  3. Click File Acquire.
  4. Click the Scan button to test your scanner.