本帖最后由 229989799 于 2017-4-17 15:04 编辑
win7测试正常。改了第十行的一个“0”。。楼主漏了15行,加了个Endfunc,否则无法运行此脚本。
MsgBox(0,0,_Gateway())
Func _Gateway()
Dim $IPGateway
Dim $objWMIService = ObjGet("winmgmts:\\.\root\CIMV2")
Dim $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = TRUE", "WQL", 0x10 + 0x20)
For $objItem In $colItems
$IPGateway = $objItem.DefaultIPGateway(0)
If StringInStr($IPGateway, ".") > 0 Then ExitLoop
Next
If StringRegExpReplace($IPGateway, '(\d+\.){12}', '') = "" Then
MsgBox ( 0 , "ERROR" , "无法获取本地网关,请检查网线是否连接且已通过认证" )
Else
Return StringRegExpReplace($IPGateway, '(\d+\.){12}', '')
EndIf
EndFunc
|