WSH » wshnetwork » AddWindowsPrinterConnection

Syntax:
Win 95/98: WshNetwork.AddWindowsPrinterConnection(strPrinterPath, strDriverName [,strPort])

Win2000/NT: WshNetwork.AddWindowsPrinterConnection (strPrinterPath)
strPrinterPath
Receives the path to a printer on the network.
strDriverName
Receives the name of the driver that will be loaded. This is required for Windows 95/98 machines. If the driver is not installed, the method will fail.
strPort
This optional parameter receives the port on which the printer exists. The default port is LPT1.

The AddWindowsPrinterConnection method adds a printer connection to Windows. This method reqires different number of arguments depending on the version of Windows the script is running on.

There are two prototypes of the AddWindowsPrinterConnection method, one for Windows 95/98, and one for Windows NT/2000. This method essentially emulates the process of adding network printer connections via Control Panel/Printers. When using this method on Windows 95/98 machines, the printer driver must already be installed or this method will fail. Unlike the AddPrinterConnection method, this method does not require a port to be specified explicitly. The default port is LPT1.

Examples

Code:
' On Windows 95/98 Machines:
strPrinterPath = "\\Server\LaserJet"
strDriverName = "HP LaserJet 4/4M Plus PS 600"
Set WshNetwork = CreateObject("WScript.Network")
WshNetwork.AddWindowsPrinterConnection strPrinterPath, strDriverName
Explanation:

This VBScript code connects to the network printer \\Server\LaserJet.

Language(s): VBScript
Code:
' On Windows NT/2000 Machines:
strPrinterPath = "\\Server\LaserJet"
Set WshNetwork = CreateObject("WScript.Network")
WshNetwork.AddWindowsPrinterConnection strPrinterPath
Explanation:

This VBScript code connects to the network printer \\Server\LaserJet.

Language(s): VBScript