在论坛上看到这样一段代码:Func _NetworkAdapterInfo()
Local $colItem
Local $objItem
Local $colItems
Local $objItems
Local $objWMIService
Local $Adapters[1][12]
$Adapters[0][0] = 0
$objWMIService = ObjGet("winmgmts:\\localhost\root\CIMV2")
$colItem = $objWMIService.ExecQuery("Select * FROM Win32_NetworkAdapter Where NetConnectionStatus >0", "WQL", 0x30)
If IsObj($colItem) Then
For $objItem In $colItem
If $objItem.MACAddress = "00:00:00:00:00:00" Then ContinueLoop
$Adapters[0][0] += 1
ReDim $Adapters[UBound($Adapters) + 1][12]
$Adapters[$Adapters[0][0]][0] += $Adapters[0][0]
$Adapters[$Adapters[0][0]][1] = $objItem.NetConnectionStatus
$Adapters[$Adapters[0][0]][2] = $objItem.Description
;MsgBox( 0, "", $objItem.Description )
$Adapters[$Adapters[0][0]][3] = $objItem.NetConnectionID
$Adapters[$Adapters[0][0]][4] = $objItem.MACAddress
$Adapters[$Adapters[0][0]][11] = $objItem.PNPDeviceID
$colItems = $objWMIService.ExecQuery('Select * FROM Win32_NetworkAdapterConfiguration Where MACAddress = "' & $Adapters[$Adapters[0][0]][4] & '" And IPEnabled = True ', "WQL", 48)
If IsObj($colItems) Then
For $objItems In $colItems
$Adapters[$Adapters[0][0]][5] = $objItems.IPAddress(0)
$Adapters[$Adapters[0][0]][6] = $objItems.DefaultIPGateway(0)
$Adapters[$Adapters[0][0]][7] = $objItems.IPSubnet(0)
$Adapters[$Adapters[0][0]][8] = $objItems.DNSServerSearchOrder(0)
$Adapters[$Adapters[0][0]][9] = $objItems.DNSServerSearchOrder(1)
$Adapters[$Adapters[0][0]][10] = $objItems.SettingID
Next
EndIf
Next
EndIf
Return $Adapters
EndFunc ;==>_NetworkAdapterInfo
现在有一个问题就是如果电脑中DNS只填了一个主DNS,另一个没有填 参数的情况下,打开就会出错:
$Adapters[$Adapters[0][0]][9] = $objItems.DNSServerSearchOrder(1)^ERROR
Error:请求动作失败(请求于对象)
本人对WMI一点不懂,努力学习中,故求解决方法。先谢了 |