标题: VBS引用对象的数组类型疑问 [打印本页]
作者: everest79 时间: 2008-11-6 00:44 标题: VBS引用对象的数组类型疑问
- Function GetIP
- Dim wmi
- Set wmi=GetObject("winmgmts:\\.\root\cimv2")
- Set wmq=wmi.ExecQuery("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled='True'")
- For Each obj in wmq
- msgbox obj.ipaddress(0) & vbCrLf & obj.defaultipgateway(0) & vbCrLf & obj.IPSubnet(0)
- msgbox Ubound(obj.IPAddress)
- For i= 0 to Ubound(obj.IPAddress)
- Msgbox obj.IPAddress(i) & obj.IPSubnet(i) & i
- Next
- Next
- End Function
复制代码
- Function GetIP
- Dim wmi
- Set wmi=GetObject("winmgmts:\\.\root\cimv2")
- Set wmq=wmi.ExecQuery("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled='true'")
- For Each obj in wmq
- msgbox obj.ipaddress(0)
- msgbox obj.ipaddress(1)
- msgbox obj.ipaddress
- Next
- 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.- strComputer = "."
- Set objWMIService = GetObject( _
- "winmgmts:\\" & strComputer & "\root\cimv2")
- Set IPConfigSet = objWMIService.ExecQuery _
- ("Select IPAddress from Win32_NetworkAdapterConfiguration ")
-
- For Each IPConfig in IPConfigSet
- If Not IsNull(IPConfig.IPAddress) Then
- For i=LBound(IPConfig.IPAddress) _
- to UBound(IPConfig.IPAddress)
- WScript.Echo IPConfig.IPAddress(i)
- Next
- End If
- 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 |