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.
' 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
This VBScript code connects to the network printer \\Server\LaserJet.
' On Windows
NT/2000 Machines:
strPrinterPath = "\\Server\LaserJet"
Set WshNetwork = CreateObject("WScript.Network")
WshNetwork.AddWindowsPrinterConnection
strPrinterPath
This VBScript code connects to the network printer \\Server\LaserJet.