返回当前的网络驱动器映射信息。
objDrives = object.EnumNetworkDrives
EnumNetworkDrives 方法返回一个集合。该集合是一个数组,它将各个项对(网络驱动器的本地名称及其相关的 UNC 名称)关联在一起。集合中的偶数项表示逻辑驱动器的本地名称。奇数项表示与之相关的 UNC 共享名。集合中第一项的索引编号为零 (0)。
下面的示例使用 EnumNetworkDrives 生成网络驱动器的列表,并显示映射信息。
<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 对象 | MapNetworkDrive 方法 | RemoveNetworkDrive 方法