Terminal Server Printing
Microsoft Windows 2000 and later supports Terminal Services, a technology that allows multiple users to connect to a single server system. This server system is called a terminal server. For a detailed discussion of Terminal Services, see the Windows SDK documentation.
If you are developing a printer minidriver or driver for Windows 2000 or later, you do not have to do anything special to support printers connected to terminal servers. However, you must follow all design, implementation, and installation guidelines specified in the Windows Driver Kit (WDK). Specifically, you must use the following rules:
If possible, support your printer by simply providing a minidriver that works with one of the following Microsoft-supplied drivers:
In Windows Vista, you must design a printer graphics DLL to execute in user mode. See Choosing User Mode or Kernel Mode.
If your device must be supported by a custom driver, your driver must adhere exactly to Microsoft's printer driver architecture. Specifically:
- You must create a printer interface DLL.
- You must create a printer graphics DLL. This DLL can execute in either user mode or kernel mode, but user mode is preferred.
- If you create kernel-mode code, you must test the code using Driver Verifier.
- You must provide an installation procedure based on setup INF files, as described in Installing and Configuring Printer Drivers.
All custom driver code must be reentrant. User-mode code should employ critical section objects (described in the Windows SDK documentation). Kernel-mode code should use semaphores (see EngCreateSemaphore and related functions).
Printer drivers and custom spooler components must access the registry only through interfaces provided specifically for these drivers and spooler components, as described in appropriate sections of the WDK.
Usually, all you need to do for installation is provide an INF file that can be read by Microsoft's printer class installer when a user invokes the Add Printer wizard. Sometimes, custom setup code (a co-installer or class installer) is also needed. If you must create custom setup code, remember the following:
Either the user or the setup code must put the terminal server into installation mode. (For more information, see the Microsoft Windows SDK documentation.)
Do not attempt to replace system files. Windows file protection prohibits system file replacement.
Avoid requiring system reboots as much as possible. Use the following guidelines:
- Do not replace driver files that have not changed. For example, files shared by several devices should not be updated if the most current version is already installed.
- If a file must be replaced, the setup code should take steps to unload the old version and then load the new version (for example, by stopping the driver service, replacing the file, then restarting the service).
- Requiring a user to log off, then re-log on, is preferable to requiring a system reboot.
For more information about co-installers and class installers, see Writing Class Installers and Co-Installers.
Note Before writing custom setup code, it is important to read the Terminal Services programming guidelines provided in the Windows SDK documentation.
User Interface Considerations
Custom setup code that is run by a user can display a user interface.
Almost all printer driver code runs in the spooler's execution context and therefore cannot display a user interface. User interfaces can be displayed only by printer interface DLLs, and only from within the following functions:
The DrvPrinterEvent function, which receives event codes identifying printer events. Note that the function can display a user interface only for the PRINTER_EVENT_ADD_CONNECTION and PRINTER_EVENT_DELETE_CONNECTION event codes.
All other printer driver code executes in the spooler's context. From this context, calling MessageBox or MessageBoxEx is allowed, but you must set MB_SERVICE_NOTIFICATION. These functions are described in the Windows SDK documentation.