How to install printer drivers from a network print server


Print servers that are based on Microsoft Windows NT technology can serve printer driver files to Windows 95, Windows 98, Windows 98 Second Edition (SE), and Windows Millennium Edition clients. This article describes how to identify, download, and install the printer driver installation on the client computer.

More Information

Windows 95 and later versions of that operating system support Point and Print. Point and Print is a facility by which a user can set up and print to a network printer without providing appropriate printer drivers. Hereafter in this article Windows 95, Windows 98, Windows 98 SE, and Windows Me will be referred to collectively as a Windows 95 client.

For more information on the usage of Point and Print features on Windows 95 clients, see "Connecting to the Shared Printer" in the following Microsoft Knowledge Base article:
141839 How to Set Up a Network Printer Using Point and Print
Point and Print is possible because driver files have been installed into the printer share on the server for a Windows 95 client printer driver installation.
For additional information on how to do this, click the article number below to view the article in the Microsoft Knowledge Base:

142667 How to Share Windows 95 Printer Driver in Windows NT 4.0/Windows 2000
Sometimes you may want to automate by programmatic methods the installation of printers on client computers that are running operating systems that are based on Windows 95. The following steps will install the printer driver files in a manner similar to the Windows 95 Point and Print installation process.

To install printer driver files from a print server, follow these steps:
  1. Identify the target printer on a print server by using a UNC path to the printer share.
  2. Get the driver installation information from the print server by calling the GetPrinterDriver function with the appropriate environment string.
  3. Check to see if the driver installation is already installed and resolve any conflicts.
  4. Determine where the driver files for the driver installation should be installed by calling the GetPrinterDriverDirectory function.
  5. Determine the location of the driver files on the print server.
  6. Copy the driver files from the print server's share to the local installation folder. The DRIVER_INFO structure that you obtained earlier provides the list of all of the driver files.
  7. Make changes to the printer driver information as may be appropriate for the local computer.
  8. Install the driver installation by calling the AddPrinterDriver function.

Step 1: Identify the target printer

Usually the target printer is specified in some manner by the user either by a name that is typed into a user interface or by selection from a list. For programmatic purposes, the UNC name of the target printer can be stored in a list or database that the program accesses. Alternatively, the UNC name of the printer can be determined by an algorithm that uses the EnumPrinters function to find the printers that are accessible on the network.

Whatever the technique used, the UNC path that identifies the printer contains both the name of the server and the name of the printer.

Step 2: Get the printer driver information

To begin the driver installation process, a program needs to know the list of driver files and the configuration of the driver files in the driver installation. This information is provided by the print server by calling the GetPrinterDriver function to initialize a DRIVER_INFO_3 buffer with the driver installation information for the shared printer.

To call the GetPrinterDriver function, a handle to the printer is required. This handle is obtained from the OpenPrinter function that uses the UNC name of the printer identified in step 1. For clients that are based on Windows 95, the second parameter to GetPrinterDriver should always be NULL because there is only one environment version of Windows 95. A DRIVER_INFO_3 buffer should be requested for Windows 95 clients because this buffer definition is used to install driver installations on all Windows 95 and later operating systems. For a discussion of how to properly call Windows Spooler functions that fill caller allocated buffers, see the following Knowledge Base article:
158828 HOWTO: How To Call Win32 Spooler Enumeration APIs Properly

Step 3: Check for a previous printer driver installation

There is a possibility that the driver installation that is identified on the print server is already installed on the Windows 95 client. If it is already installed, it may not be necessary to reinstall the driver files. When the Point and Print installation encounters this conflict, it raises a dialog box to resolve the conflict by offering to either keep the existing driver or replace it. The recommended action is to keep the existing driver files because there is a presumption that they are used by existing printer installations on the client.

Printer driver replacement is a complex topic because it requires overwriting the driver files. Driver files cannot be overwritten if they are in use. To free the driver installation from use, no printer installations can be using the printer drivers. This article discusses how to add printer drivers, but it does not discuss how to replace printer drivers.

Step 4: Get the destination for the printer driver files

The AddPrinterDriver function looks for the driver files at a specific location on the Windows 95 client. The printer driver files must be copied to this location. The path for the printer driver files is provided by the GetPrinterDriverDirectory function. Passing the NULL pointer value to the pName parameter of this function causes it to return the local printer driver folder where AddPrinterDriver expects to find the driver files.

Step 5: Locate the printer driver files on the server

Generally, the location of printer driver files on a print server can be found by calling the GetPrinterDriverDirectory function and passing the server name in the pName parameter. Unfortunately, on Windows 95 clients, the remote or server part of this function is not implemented. The pName parameter must always be passed a NULL pointer value and it always returns the local printer driver directory. Because the GetPrinterDriverDirectory function cannot return the network path to the server's driver folders, the application must build its own network path.

On Microsoft Windows NT and Windows 2000 print servers, the printer driver files are shared in a directory tree on the print$ share. This share is invisible, so it is not listed during a user's network browse activity. The Windows 95 printer driver files are located on this share under the folder named Win40 for the Windows 4.0 environment. The driver files are located in the subfolder named 0 (zero). Zero is the driver architecture revision for Windows 95 printer drivers.

For Windows 95 based clients, the network path to the printer driver files on the server is of the \\<server>\print$\win40\0 form, where <server> is a placeholder for the name of the print server.

Step 6: Copy the printer driver files

All of the files that are used by a printer driver installation are listed in the DRIVER_INFO_3 structure that you obtained in step 2. To copy the driver files from the server to the local Windows 95 client printer driver folder, just extract the file names for the driver files from all of the relevant string fields in DRIVER_INFO_3.

For each file name that is extracted, form a full UNC network source path to the file by using the network path that you determined in step 5. Using the same file name, form a local destination path by using the file name and the local printer driver folder that you obtained in step 4.

For Windows 95 clients, the structure that is returned from the print server contains file names only. However, on other client operating systems you may find full paths given in the driver file name fields. These paths need to be stripped from the file names before you form the source and destination paths.

Note that the pDependentFiles member of DRIVER_INFO_3 may list multiple file names by separating each file name string with a zero (NULL) terminator. The end of the list of files in this member is denoted by a double NULL terminator.

Use the Win32 CopyFile function to copy each driver file from the server to the local computer.

Error handling should be built into this process. Examples of some error cases that should be handled are as follows:
  • The source network path may become unavailable.
  • The source file may not exist, although it is listed in the driver information.
  • The local file name may already exist.
A previous instance of a printer driver file on the local computer is a case that deserves special attention. There are three options to handle this case:

  • Fail the file copying and the driver installation.
  • Attempt to overwrite the file.
  • Continue to copy files and use the file that is already installed instead of the file that is located on the server.
Note that this is a different problem than the case of a duplicate printer driver installation, which was discussed in step 3.

In many cases, a file of the same name may indeed be the same file that can be shared between printer driver installations. Many printer drivers that ship with the operating system share a common driver file. UniDrv.dll and Pscript.dll are examples of such driver files. Alternatively, a driver file of the same name may be a legitimate file naming conflict.

One method of resolving this conflict is to use the driver file that already exists on the system. This approach ensures that only the new printer installation and not the existing printer installation degrades due to driver file incompatibility.

Step 7: Change local printer driver information

If necessary, make changes to the driver information for this installation on the Windows 95 client. In most cases the information that is obtained from the print server should be sufficient.

Some things that may be changed for the local installation include the name of the driver installation and the default data type.

Note also that the file names in the DRIVER_INFO_3 structure may have full path information on clients other than Windows 95. These full paths need to be removed from the file names in the driver information before you call the AddPrinterDriver function.

Step 8: Install the Printer Driver

After the driver files have been copied to the local printer driver folder and the appropriate DRIVER_INFO_3 buffer is ready, call AddPrinterDriver to install the printer driver. A successful call to AddPrinterDriver installs a printer driver installation that can be referenced by the pName member of the DRIVER_INFO_3 structure. If the AddPrinterDriver function fails, call the GetLastError function to attempt to diagnose the cause. Some common causes of function failure are duplicate driver installation names or missing components that are referenced in the DRIVER_INFO_3 buffer.

Using the Printer Driver Installation

To install a printer using this printer driver, use the printer driver installation name (the pName) string from the DRIVER_INFO_3 structure to name the printer driver to use for the new printer. Specify the printer driver installation name in the PRINTER_INFO_2 structure's pDriverName member when you call AddPrinter.

Finally, this discussion assumes that the program code will execute only on Windows 95 clients. This assumption is made because that is the platform on which Point and Print requires the separate download of printer drivers. The process can be used on Windows NT clients if the differences in the client platform are considered. Some of these differences are the full file name paths in the DRIVER_INFO_3 structure, a variety of environments relating to microprocessor types, appropriate use of different structure levels, and the location of driver files in the server's printer driver share. However, adding printer drivers to a Windows NT or Windows 2000 client in this manner is unnecessary. NT printer connections should be used on these clients, because NT printer connections provide a superior means of printer and print job management and can be easily added to a client with a single call to AddPrinterConnection by using the UNC path to the printer that is found in Step 1.

Id. de artículo: 203604 - Última revisión: 12 jun. 2009 - Revisión: 1