找回密码
 注册
搜索
[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
查看: 12657|回复: 2

VBS引用对象的数组类型疑问

[复制链接]
发表于 2008-11-6 00:44:10 | 显示全部楼层 |阅读模式

  1. Function GetIP
  2. Dim wmi
  3. Set wmi=GetObject("winmgmts:\\.\root\cimv2")
  4. Set wmq=wmi.ExecQuery("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled='True'")
  5. For Each obj in wmq
  6.     msgbox obj.ipaddress(0) & vbCrLf & obj.defaultipgateway(0) & vbCrLf & obj.IPSubnet(0)
  7.     msgbox Ubound(obj.IPAddress)
  8.     For i= 0 to Ubound(obj.IPAddress)
  9.            Msgbox obj.IPAddress(i) & obj.IPSubnet(i) & i
  10.     Next
  11. Next
  12. End Function
复制代码


  1. Function GetIP
  2. Dim wmi
  3. Set wmi=GetObject("winmgmts:\\.\root\cimv2")
  4. Set wmq=wmi.ExecQuery("Select * From Win32_NetworkAdapterConfiguration  Where IPEnabled='true'")
  5. For Each obj in wmq
  6. msgbox obj.ipaddress(0)
  7. msgbox obj.ipaddress(1)
  8. msgbox obj.ipaddress
  9. Next
  10. End Function
复制代码


例一中obj.ipaddress的上限也为0,但被识别为一个数组,是否IP地址这样的类型是一个特殊的类型
发表于 2008-11-6 10:07:06 | 显示全部楼层
Use the Win32_NetworkAdapterConfiguration class and check the value of the IPAddress property. This is returned as an array, so use a For-Each loop to get the value.
  1. strComputer = "."
  2. Set objWMIService = GetObject( _
  3.     "winmgmts:\" & strComputer & "\root\cimv2")
  4. Set IPConfigSet = objWMIService.ExecQuery _
  5.     ("Select IPAddress from Win32_NetworkAdapterConfiguration ")

  6. For Each IPConfig in IPConfigSet
  7.     If Not IsNull(IPConfig.IPAddress) Then
  8.         For i=LBound(IPConfig.IPAddress) _
  9.             to UBound(IPConfig.IPAddress)
  10.                 WScript.Echo IPConfig.IPAddress(i)
  11.         Next
  12.     End If
  13. Next
复制代码

http://msdn.microsoft.com/en-us/library/aa394595.aspx

[ 本帖最后由 rat 于 2008-11-6 10:12 编辑 ]
 楼主| 发表于 2008-11-6 20:24:23 | 显示全部楼层
谢谢rat,原来这个值是打注册表返回的特殊类型
您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|批处理之家 ( 渝ICP备10000708号 )

GMT+8, 2026-3-17 02:45 , Processed in 0.008517 second(s), 8 queries , File On.

Powered by Discuz! X3.5

© 2001-2026 Discuz! Team.

快速回复 返回顶部 返回列表