返回当前网络打印机的映射信息。
objPrinters = object.EnumPrinterConnections
EnumPrinterConnections 方法返回一个集合。该集合是一个数组,它将各个项对(网络打印机的本地名称及其相关的 UNC 名称)关联在一起。集合中的偶数项表示打印机的端口。奇数项则表示网络打印机的 UNC 名称。集合中第一项的索引编号为零 (0)。
下面的示例使用 EnumPrinterConnections 方法生成网络打印机的列表,并显示映射信息。
<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>
运行脚本 | WshNetwork 对象 | AddPrinterConnection 方法 | AddWindowsPrinterConnection 方法 | RemovePrinterConnection 方法 | SetDefaultPrinter 方法