Microsoft® Windows® Script Host
AddWindowsPrinterConnection Method
WSH Reference
Version 2

Applies To


Description
Adds a printer connection to Windows.
Syntax
Windows NT/Windows 2000:
object.AddWindowsPrinterConnection(strPrinterPath)

Windows 95/98:
object.AddWindowsPrinterConnection(strPrinterPath, strDriverName[,strPort])
Parameters
Part Description
object WshNetwork object.
strPrinterPath Path to the printer.
strDriverName Name of the driver to use. Required on Windows 95/98; ignored if used on Windows NT/Windows 2000.
strPort Optional. Specifies the port to which to attach the printer on Windows 95/98. Default is LPT1. Ignored if used on Windows NT/Windows 2000.
Remarks
Using this method is the same as using the Control Panel/Printers to add a printer connection. Unlike the AddPrinterConnection method, this method allows you to create a printer connection without directing it to a specific port such as LPT1. If the connection fails, an error occurs.

In Windows 95/98 the printer driver must already be installed on the machine in order for the AddWindowsPrinterConnection method to work. If the driver is not installed Windows will return the error message "Unknown printer driver".

Example
The following example uses the AddWindowsPrinterConnection method to connect a network printer to LPT1.
Set WshNetwork = CreateObject("WScript.Network")
PrinterPath = "\\printserv\DefaultPrinter"
PrinterDriver = "Lexmark Optra S 1650"
WshNetwork.AddWindowsPrinterConnection PrinterPath, PrinterDriver