获取网卡ID[已解决]
本帖最后由 yikang8888 于 2010-12-22 15:49 编辑哪位高手指点一下,下面的代码,,在出现多个设备时会弹出对话框让选择,但我不想在选择的里面出现
ID为{000000000000000000000}的这一项,请问是那边有问题,感谢
#include <GUIConstantsEx.au3>
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
MsgBox(0, "当前选择网卡索引", '[' & NICIndex() & ']')
Exit
Func NICIndex()
Local $test, $iNICIndex
$test=_UpCmpLanNameIDInfo()
If $test = 0 Then
MsgBox(0x10, "错误", "获取网络适配器设置失败,请检查网卡驱动。")
Exit 2
ElseIf $test = 1 Then
$iNICIndex = $test
Else
; 创建“网卡选择”窗口
Local $hNICWnd, $hOKButton, $hIfTable
$hNICWnd = GUICreate("测试" & " - 网卡选择", 404, 118)
GUICtrlCreateLabel("检测到本机安装有多个网络适配器,请选择用于更新的网卡。", 16, 16, 340, 24)
$hIfTable = GUICtrlCreateCombo("", 16, 48, 372, 12 * $test, BitOR($GUI_SS_DEFAULT_COMBO, $CBS_DROPDOWNLIST))
For $i = 1 To $test
GUICtrlSetData(-1, $test[$i] & ". " & $test[$i])
Next
GUICtrlSetData(-1, $test & ". " & $test)
$hOKButton = GUICtrlCreateButton("确定(&O)", 165, 80, 76, 22, $BS_DEFPUSHBUTTON)
; 窗口事件
GUISetState(@SW_SHOW)
While 1
Switch GUIGetMsg()
Case $hOKButton, $GUI_EVENT_CLOSE
$iNICIndex = GUICtrlRead($hIfTable)
ExitLoop
EndSwitch
WEnd
GUIDelete($hNICWnd)
$iNICIndex = StringLeft($iNICIndex, StringInStr($iNICIndex, ".") - 1)
EndIf
EndFunc
Func _UpCmpLanNameIDInfo()
Local $colItems = ""
Local $strComputer = "localhost"
Local $objWMIService
Local $wbemFlagReturnImmediately = 0x10
Local $wbemFlagForwardOnly = 0x20
Local $UpCmprAdapterID = 0
Local $UpCmprAdapterHostName = ""
Local $UpCmpLanNameID
$UpCmpLanNameID = 0
$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")
$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_TSNetworkAdapterListSetting", "WQL", _
$wbemFlagReturnImmediately + $wbemFlagForwardOnly)
If IsObj($colItems) Then
For $objItem In $colItems
$UpCmpLan = $objItem.Description
$UpCmpID = $objItem.NetworkAdapterID
$UpCmprAdapterID += 1
$UpCmpLanNameID = $UpCmprAdapterID
$UpCmpLanNameID[$UpCmprAdapterID] = $UpCmpLan
$UpCmpLanNameID[$UpCmprAdapterID] = $UpCmpID
Next
EndIf
Return $UpCmpLanNameID
EndFunc ;==>_UpCmpLanNameIDInfo 本帖最后由 the886 于 2010-12-22 12:37 编辑
For $i = 1 To $test
if $test[$i] <> "{000000000000000000000}" then
GUICtrlSetData(-1, $test[$i] & ". " & $test[$i])
endif
Next
方法是这个 $test[$i]不懂对不对 是啊!数组有点搞不明白. C:\Documents and Settings\admin\桌面\IP_ID获取.au3(21,22) : 错误: 表达式错误 (不合规定的字符)
If $test[$i] <> {
~~~~~~~~~~~~~~~~~~~^
C:\Documents and Settings\admin\桌面\IP_ID获取.au3 - 1 error(s), 0 warning(s) 回复 2# the886
C:\Documents and Settings\admin\桌面\IP_ID获取.au3(21,22) : 错误: 表达式错误 (不合规定的字符)
If $test[$i] <> {
~~~~~~~~~~~~~~~~~~~^
C:\Documents and Settings\admin\桌面\IP_ID获取.au3 - 1 error(s), 0 warning(s) 回复 5# yikang8888
.......{000000000000000000000}这个是字符,要用引号" " ,还有,你可以用msgbox(0,"",$test[$i]) 来显示,是不是你想要的值 谢谢{:face (411):}
页:
[1]