Board logo

标题: VBS引用对象的数组类型疑问 [打印本页]

作者: everest79    时间: 2008-11-6 00:44     标题: 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    时间: 2008-11-6 10:07

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 编辑 ]
作者: everest79    时间: 2008-11-6 20:24

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




欢迎光临 批处理之家 (http://bbs.bathome.net/) Powered by Discuz! 7.2