Returns the current network printer mapping information.
objPrinters = object.EnumPrinterConnections
The EnumPrinterConnections method returns a collection. This collection is an array that associates pairs of items network printer local names and their associated UNC names. Even-numbered items in the collection represent printer ports. Odd-numbered items represent the networked printer UNC names. The first item in the collection is at index zero (0).
The following example uses the EnumPrinterConnections method to generate a list of networked printers and displays this mapping information.
<package> <job id="vbs"> <script language="VBScript"> Set WshNetwork = WScript.CreateObject("WScript.Network") Set oDrives = WshNetwork.EnumNetworkDrives Set oPrinters = WshNetwork.EnumPrinterConnections
WScript.Echo "Network drive mappings:" For i = 0 to oDrives.Count - 1 Step 2 WScript.Echo "Drive " & oDrives.Item(i) & " = " & oDrives.Item(i+1) Next WScript.Echo WScript.Echo "Network printer mappings:" For i = 0 to oPrinters.Count - 1 Step 2 WScript.Echo "Port " & oPrinters.Item(i) & " = " & oPrinters.Item(i+1) Next </script> </job> <job id="js"> <script language="JScript"> var WshNetwork = WScript.CreateObject("WScript.Network"); var oDrives = WshNetwork.EnumNetworkDrives(); var oPrinters = WshNetwork.EnumPrinterConnections
(); WScript.Echo("Network drive mappings:"); for(i = 0; i < oDrives.length; i += 2) { WScript.Echo("Drive " + oDrives.Item(i) + " = " + oDrives.Item(i + 1)); } WScript.Echo(); WScript.Echo("Network printer mappings:"); for(i = 0; i < oPrinters.length; i += 2) { WScript.Echo("Port " + oPrinters.Item(i) + " = " + oPrinters.Item(i + 1)); } </script> </job> </package>
Running Your Scripts | WshNetwork Object | AddPrinterConnection Method | AddWindowsPrinterConnection Method | RemovePrinterConnection Method | SetDefaultPrinter Method