[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

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

  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地址这样的类型是一个特殊的类型

谢谢rat,原来这个值是打注册表返回的特殊类型

TOP

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 编辑 ]

TOP

返回列表