展示集合中指定的项目。
Object.Item(natIndex)
Item 是每个集合的默认属性。对于 EnumNetworkDrive 和 EnumPrinterConnections 集合来说,索引是一个整数;对 Environment 和 SpecialFolders 集合来说,索引是一个字符串。
如果请求的文件夹 (strFolderName) 不可用,则 WshShell.SpecialFolders.Item (strFolderName) 在 VBScript 中返回 "Empty",而在 JScript 中返回 "undefined"。
下表列出了特殊文件夹以及支持它们的 Windows 版本。
文件夹 | Windows 版本 |
---|---|
AllUsersDesktop | Windows 2000 |
AllUsersStartMenu | Windows 2000 |
AllUsersPrograms | Windows 2000 |
AllUsersStartup | Windows 2000 |
Desktop | Windows 98/ME,Windows 2000 |
Favorites | Windows 98/ME,Windows 2000 |
Fonts | Windows 98/ME,Windows 2000 |
My Documents | Windows 98/ME,Windows 2000 |
NetHood | Windows 98/ME,Windows 2000 |
PrintHood | Windows 98/ME,Windows 2000 |
Programs | Windows 98/ME,Windows 2000 |
Recent | Windows 98/ME, Windows 2000 |
SendTo | Windows 98/ME,Windows 2000 |
Start Menu | Windows 98/ME,Windows 2000 |
StartupB | Windows 2000 |
Templates | Windows 2000 |
下面的代码显示驱动器和打印机的网络映射信息。
<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(); 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>
EnumNetworkDrive 方法 | EnumPrinterConnections 方法 | Environment 属性 | SpecialFolders 属性