请教获取本地连接的名字成为变量的方法
本帖最后由 fjvip 于 2009-9-7 11:13 编辑通常AU3中修改IP、子网掩码、网关、主DNS、备DNS我们都会。但是在这样的语句中,如何获取本地连接网卡的名称成为一个难题,希望高手能指点,在下列语句中,“本地连接”使用变量,将应该如何获名这个网卡名称?
RunWait(@ComSpec&" /c "&'netsh interface ip set address name="本地连接" source=static addr='&$IP&' mask='&$Mask,"",@SW_HIDE)
RunWait(@ComSpec&" /c "&'netsh interface ip set address name="本地连接" gateway='&$Gateway&' gwmetric=0',"",@SW_HIDE)
RunWait(@ComSpec&" /c "&'netsh interface ip set dns name="本地连接" source=static addr='&$pDNS&' register=PRIMARY',"",@SW_HIDE)
RunWait(@ComSpec&" /c "&'netsh interface ip add dns name="本地连接" addr='&$sDNS,"",@SW_HIDE)
RunWait(@ComSpec&" /c "&'netsh interface ip set wins name="本地连接" source=static addr=none',"",@SW_HIDE)复制代码$IP(IP地址)
$Mask(子网掩码)
$Gateway(默认网关)
$pDNS(主DNS)
$sDNS(副DNS)
请教获取本地连接的名字成为变量的方法 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
MsgBox(0, '本地连接名:', $netn)
EndIf
Next
EndIf 经过3个系统测试,楼上源码切实可行! 非常感激各位的帮忙已经成功解决了。。谢谢,谢谢。。。
;获取网卡名称
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 & @CRLF, "1")
RunWait('netsh interface ip set dns name = ' & $netn & 'source = static addr = ' & $Dns & ' register = PRIMARY', "c:\windows\system32", @SW_HIDE)
GUICtrlSetData($Edit4_1, "6、修改DNS2为: " & $Dns & @CRLF, "1")
RunWait('netsh interface ip add dns name = ' & $netn & 'addr = ' & $Dns & ' index=2', "c:\windows\system32", @SW_HIDE) 呵呵,学习一下。。 多网卡怎么搞呀? 学习了,这有点难!!! 学习了,呵呵, 运行出错:
Variable must be of type "Object".:
$colitems = $objWMIService.ExecQuery ('SELECT * FROM Win32_NetworkAdapter', 'WQL', 0x10 + 0x20)
$colitems = $objWMIService^ ERROR
页:
[1]