Adding and Deleting Printer Connections

Microsoft® Windows® 2000 Scripting Guide

Using WSH methods as part of a logon script can ensure that the printer connections are properly configured for each user. Several WSH methods, including AddWindowsPrinterConnection and RemovePrinterConnection, can be used to manage printer connections on client computers.

These methods are typically used in logon scripts, and for two reasons:

  • WSH methods do not normally work against remote computers (although you can use the WshController object to run scripts remotely). To manage printer connections by using these methods, the script must be run locally.

  • Printers are configured independently for each user and are stored in the user profile. When you enumerate printers using WSH or WMI, you actually enumerate them on a per-user basis rather than a per-computer basis. Using the WSH methods as part of a logon script ensures that the printer connections are properly configured for each user.

Including the methods in a logon script enables you to dynamically adjust printer connections each time a user logs on. For example, if you install a new printer for a department, you can add code to the logon script for each user in the department that creates a new connection to a printer. If you delete a printer, you can add code that automatically removes any connections to that printer. This prevents the problems that can arise from users attempting to print to a printer that no longer exists.