Microsoft Windows Script Host 2.0 | 语言参考 |
从集合中返回指定的项。
object.Item(natIndex)
object
EnumNetworkDrive 或 EnumPrinterConnections 方法的结果,或者是 Environment 或 SpecialFolders 属性返回的对象。
natIndex
要检索的项。
Item 是每个集合的缺省属性。对于 EnumNetworkDrive 和 EnumPrinterConnections 集合,index 是一个整数; 对于 Environment 和 SpecialFolders 集合,index 是一个字符串。
如果所请求的文件夹 (strFolderName) 不可用,WshShell.SpecialFolders.Item("strFolderName") 将返回 NULL。例如 Windows 95/98 没有 AllUsersDesktop 文件夹,如果 strFolderName = AllUsersDesktop,返回的将是 NULL。
下表列出了若干特殊的文件夹,以及提供它们的 Windows 版本:
文件夹 | Windows 版本 |
---|---|
AllUsersDesktop | Windows 2000 |
AllUsersStartMenu | Windows 2000 |
AllUsersPrograms | Windows 2000 |
AllUsersStartup | Windows 2000 |
Desktop | Windows 95/98, Windows 2000 |
Favorites | Windows 95/98, Windows 2000 |
Fonts | Windows 95/98, Windows 2000 |
My Documents | Windows 95/98, Windows 2000 |
NetHood | Windows 95/98, Windows 2000 |
PrintHood | Windows 95/98, Windows 2000 |
Programs | Windows 95/98, Windows 2000 |
Recent | Windows 95/98, Windows 2000 |
SendTo | Windows 95/98, Windows 2000 |
Start Menu | Windows 95/98, Windows 2000 |
StartupB | Windows 2000 |
Templates | Windows 2000 |
下例演示了如何在两个使用不同脚本语言(VBScript and JScript)的任务中使用同一个 .wsf 文件。这两个任务的功能相同——显示当前机器的域名、计算机名、用户名及其驱动器和打印机的网络映射信息:
<package>
<job id="vbs">
<script language="VBScript">
Set WshNetwork = WScript.CreateObject("WScript.Network")
Set oDrives = WshNetwork.EnumNetworkDrives
Set oPrinters = WshNetwork.EnumPrinterConnections
WScript.Echo "Domain = " & WshNetwork.UserDomain
WScript.Echo "Computer Name = " & WshNetwork.ComputerName
WScript.Echo "User Name = " & WshNetwork.UserName
WScript.Echo
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="Javascript">
var WshNetwork = new ActiveXObject("WScript.Network");
var oDrives = WshNetwork.EnumNetworkDrives();
var oPrinters = WshNetwork.EnumPrinterConnections();
WScript.Echo("Domain = " + WshNetwork.UserDomain);
WScript.Echo("Computer Name = " + WshNetwork.ComputerName);
WScript.Echo("User Name = " + WshNetwork.UserName);
WScript.Echo();
WScript.Echo("Network drive mappings:");
for(i=0; i<oDrives.Count(); i+=2){
WScript.Echo("Drive " + oDrives.Item(i) + " = " + oDrives.Item(i+1));
}
WScript.Echo();
WScript.Echo("Network printer mappings:");
for(i=0; i<oPrinters.Count(); i+=2){
WScript.Echo("Port " + oPrinters.Item(i) + " = " + oPrinters.Item(i+1));
}
</script>
</job>
</package>
详细信息请参阅:运行脚本
应用于: EnumNetworkDrive 方法 | EnumPrinterConnections 方法 | Environment 属性 | SpecialFolders 属性