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)
NextAddPrinterConnection
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 ... |
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access