本帖最后由 fjvip 于 2009-9-7 11:14 编辑
下面一段代码是修改IP地址的,可是很遗憾的是,不够人性化,经常有时候因为摄像头驱动的影响,本地连接,经常名称是“本地连接 2”这样的名称,而下面,是针对“本地连接”修改IP的。所以不够灵活。希望高手能使用AU3获取网卡名称,传给一个变量值。
;修改IP
GUICtrlSetData($Edit4_1, "2、修改IP地址为: " & $sdip & @CRLF, "1")
Sleep(500)
GUICtrlSetData($Edit4_1, "3、修改子网掩码为: " & $mask & @CRLF, "1")
Sleep(500)
GUICtrlSetData($Edit4_1, "4、修改网关为: " & $gateway & @CRLF, "1")
RunWait('netsh interface ip set address name = "本地连接" source = static addr = ' & $sdip & ' mask = ' & $mask & ' gateway = ' & $gateway & ' gwmetric = 0', "c:\windows\system32", @SW_HIDE)
GUICtrlSetData($Edit4_1, "5、修改DNS1为: " & $Dns[1] & @CRLF, "1")
RunWait('netsh interface ip set dns name = "本地连接" source = static addr = ' & $Dns[1] & ' register = PRIMARY', "c:\windows\system32", @SW_HIDE)
GUICtrlSetData($Edit4_1, "6、修改DNS2为: " & $Dns[2] & @CRLF, "1")
RunWait('netsh interface ip add dns name = "本地连接" addr = ' & $Dns[2] & ' index=2', "c:\windows\system32", @SW_HIDE)
解决方法如下:(在这里感谢提供方法的朋友。谢谢。)
;获取网卡名称
Dim $objwmiservice = ObjGet('winmgmts:\\localhost\root\CIMV2'), $netn
$colitems = $objwmiservice.ExecQuery('SELECT * FROM Win32_NetworkAdapter', 'WQL', 0x10 + 0x20)
If IsObj($colitems) Then
For $objitem In $colitems
If $objitem.netconnectionid <> '' Then
$netn = $objitem.netconnectionid
EndIf
Next
EndIf
;修改IP
GUICtrlSetData($Edit4_1, "2、修改IP地址为: " & $sdip & @CRLF, "1")
Sleep(500)
GUICtrlSetData($Edit4_1, "3、修改子网掩码为: " & $mask & @CRLF, "1")
Sleep(500)
GUICtrlSetData($Edit4_1, "4、修改网关为: " & $gateway & @CRLF, "1")
RunWait('netsh interface ip set address name = ' & $netn & ' source = static addr = ' & $sdip & ' mask = ' & $mask & ' gateway = ' & $gateway & ' gwmetric = 0', "c:\windows\system32", @SW_HIDE)
GUICtrlSetData($Edit4_1, "5、修改DNS1为: " & $Dns[1] & @CRLF, "1")
RunWait('netsh interface ip set dns name = ' & $netn & ' source = static addr = ' & $Dns[1] & ' register = PRIMARY', "c:\windows\system32", @SW_HIDE)
GUICtrlSetData($Edit4_1, "6、修改DNS2为: " & $Dns[2] & @CRLF, "1")
RunWait('netsh interface ip add dns name = ' & $netn & ' addr = ' & $Dns[2] & ' index=2', "c:\windows\system32", @SW_HIDE) |