Compartir a través de


EnumPrinterConnections Method

Returns the current network printer mapping information.

                      objPrinters = object.EnumPrinterConnections 

Arguments

  • object
    WshNetwork object.

  • objPrinters
    Variable that holds the network printer mapping information.

Remarks

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).

Example

Description

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>

Applies To:

WshNetwork Object

See Also

Concepts

Running Your Scripts

Reference

AddPrinterConnection Method

AddWindowsPrinterConnection Method

RemovePrinterConnection Method

SetDefaultPrinter Method