Network Printer-Related Functions
WSH provides access to connected network printers in a similar fashion to network drives. You can enumerate (list), add, and remove network printer connections. The network printers are connected to a specified printer port, such as LPT1.
Warning
These connected printers are not the same as printers added using
Control Panel settings, so they are not accessible to Windows
applications and are therefore of limited use. The
SetDefaultPrinter
method uses the Control Panel
printer settings. Future versions of WSH will support manipulation of
Windows printers.
EnumPrinterConnections
The
EnumPrinterConnections
method returns a special WSH
collection with a format similar to the one described for the
EnumNetworkDrives
method. It lists the printer
port and connected network printer information.
Set objNetwork = CreateObject("Wscript.Network") Set objPrinters = objNetwork.EnumPrinterConnections( ) 'loop through and display all connected printers For nF = 0 To objPrinters.Count - 1 Step 2 Debug.Print objPrinters(nF) & _ " is connected to " & objPrinters(nF + 1) Next
AddPrinterConnection
The
AddPrinterConnection
method connects a port to a specified
shared network printer.
objNetwork.AddPrinterConnection(strPrinterPort
,strRemoteName
, _ [bUpdateProfile
], [bUserName
], [bPassword
])
Table 9-17 lists the parameters for the
AddPrinterConnection
method.
Table 9-17. AddPrinterConnection parameters
Parameter |
Description |
---|---|
|
Local drive letter to ... |
Get Windows XP in a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.