Microsoft Windows Script Host 2.0 | 语言参考 |
返回被枚举项的个数。
object.Count
object
EnumNetworkDrive 或 EnumPrinterConnections 方法的结果, 或者是 Arguments 属性返回的对象。
在 JScript 中,Count 属性被实现为一个方法,而不是属性(象在 VBScript 中那样)。因此,在 JScript 中使用 Count 时需要在语句的后面添加括号,如下例所示:
objArgs.Count()
下例演示了如何在两个使用不同脚本语言(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>
详细信息请参阅:运行脚本
应用于: EnumNetworkDrives 方法 | EnumPrinterConnections 方法 | Arguments 属性