请教如何避免如win2003系统下获取第二DNS地址失败,提示“请求于对象”!(已解决)
本帖最后由 txm888 于 2011-12-20 17:41 编辑;======================================================
;
; 函数名称: _NetworkAdapterInfo()
; 详细信息: 获得网卡信息
; 返回值说明:
; 以二维数组方式返回.例如 $info=_NetworkAdapterInfo()
; $info=网卡数量
; $info第一块网卡的标志1
; $info第二块网卡的标志2
; $info第一块网卡的网卡名称
; $info第二块网卡的网卡名称
; $info第一块网卡的默认网关
; $info第一块网卡的DNS主机名称(本机名称)
; $info第一块网卡的IP地址
; $info第一块网卡的主DNS
; $info第一块网卡的次DNS
; $info第一块网卡的子网掩码
; $info第一块网卡的MAC地址
; $info第一块网卡的连接名称
; 注意,此UDF不会获取已经禁用的网卡。
; 如果有需要,请删除' WHERE IPEnabled != 0'和' WHERE NetConnectionStatus >0'
; 作者: thesnow(rundll32@126.com)
;
;======================================================
Func _NetworkAdapterInfo()
Local $colItems = ""
Local $objWMIService
Local $NetworkAdapterID = 0
Local $NetworkAdapterName = ""
Local $NetworkAdapterGateway = ""
Local $NetworkAdapterHostName = ""
Local $NetworkAdapterIPaddress = ""
Local $NetworkAdapterDNS1 = ""
Local $NetworkAdapterDNS2 = ""
Local $NetworkAdapterSubnet = ""
Local $NetworkAdapterMAC = ""
Local $NetworkAdapterNetConnectionID = ""
Local $NetworkAdapterInfo ;最高10块网卡.
$NetworkAdapterInfo = 0
$objWMIService = ObjGet("winmgmts:\\localhost\root\CIMV2")
$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled != 0", "WQL", 0x10 + 0x20)
Local $colItem2 = $objWMIService.ExecQuery('SELECT * FROM Win32_NetworkAdapter WHERE NetConnectionStatus >0', "WQL", 0x10 + 0x20)
If IsObj($colItems) Then
For $objItem In $colItems
$NetworkAdapterName = $objItem.Description
$NetworkAdapterGateway = $objItem.DefaultIPGateway(0)
$NetworkAdapterHostName = $objItem.DNSHostName
$NetworkAdapterIPaddress = $objItem.IPAddress(0)
$NetworkAdapterDNS1 = $objItem.DNSServerSearchOrder(0)
$NetworkAdapterDNS2 = $objItem.DNSServerSearchOrder(1)
$NetworkAdapterSubnet = $objItem.IPSubnet(0)
$NetworkAdapterMAC = $objItem.MACAddress
$NetworkAdapterID += 1
$NetworkAdapterInfo = $NetworkAdapterID
$NetworkAdapterInfo[$NetworkAdapterID] = $NetworkAdapterID
$NetworkAdapterInfo[$NetworkAdapterID] = $NetworkAdapterName
$NetworkAdapterInfo[$NetworkAdapterID] = $NetworkAdapterGateway
$NetworkAdapterInfo[$NetworkAdapterID] = $NetworkAdapterHostName
$NetworkAdapterInfo[$NetworkAdapterID] = $NetworkAdapterIPaddress
$NetworkAdapterInfo[$NetworkAdapterID] = $NetworkAdapterDNS1
$NetworkAdapterInfo[$NetworkAdapterID] = $NetworkAdapterDNS2
$NetworkAdapterInfo[$NetworkAdapterID] = $NetworkAdapterSubnet
$NetworkAdapterInfo[$NetworkAdapterID] = $NetworkAdapterMAC
Next
Else
Return $NetworkAdapterInfo
EndIf
If IsObj($colItem2) Then
$NetworkAdapterID = 0
For $objItem2s In $colItem2
$NetworkAdapterNetConnectionID = $objItem2s.NetConnectionID
$NetworkAdapterID += 1
$NetworkAdapterInfo[$NetworkAdapterID] = $NetworkAdapterNetConnectionID
Next
Return $NetworkAdapterInfo
Else
Return $NetworkAdapterInfo
EndIf
EndFunc ;==>_NetworkAdapterInfo问题在于这行$NetworkAdapterDNS2 = $objItem.DNSServerSearchOrder(1),比如在win2003系统下,若只设置第一DNS地址,不设置第二DNS地址,会导致请求对象失败,,,为了兼容更多系统能检查到第二DNS地址,同时又能避免此类问题再发生,请问各位大侠,有没有方法检测$objItem.DNSServerSearchOrder(1)这项是有效的?谢谢啦。。。 成也WMI,败也WMI 回复 2# 80ren
现在问题是如何让败的WMI重新站起来{:face (355):} 请大牛们进来支招啊,,,小弟我被该问题困扰了,实在不知道怎么解决 晕晕了,这问题好急,请大侠们出出手啊, 回复 5# txm888
方法已找到,谢谢各位,请参照此贴:http://www.autoitx.com/forum.php?mod=viewthread&tid=25206&highlight=dns
页:
[1]