找回密码
 加入
搜索
楼主: qw5838132

[AU3基础] netsh 设置多网卡问题 【已解决】

[复制链接]
 楼主| 发表于 2020-3-24 16:15:05 | 显示全部楼层
floor6ggg 发表于 2020-3-24 11:51
试试:
应该是在第43行的代码,

可以了,用了你的代码,都不需要建文本了,非常感谢,研究好几天了
 楼主| 发表于 2020-3-24 16:16:22 | 显示全部楼层
把完整代码贴出来,给有需要的人
#RequireAdmin
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiIPAddress.au3>
#include <StaticConstants.au3>
#include <ComboConstants.au3>
#include <GuiStatusBar.au3>
#include <Array.au3>
#include <MsgBoxConstants.au3>
#include <WinAPIFiles.au3>

#Region ### START Koda GUI section ###Form=
Global Const $aArray = GetAdapterProperty()
;$wenjian = @ScriptDir & "\ceshi.txt"    ;新建文本到当前脚本位置
$Form1 = GUICreate("Form1", 615, 438, 192, 124)
$Button1 = GUICtrlCreateButton("确定", 440, 328, 75, 25)
$IPAddress1 = _GUICtrlIpAddress_Create($Form1, 96, 128, 130, 21) ;80
_GUICtrlIpAddress_Set($IPAddress1, "192.168.0.0")
$IPAddress2 = _GUICtrlIpAddress_Create($Form1, 96, 176, 130, 21) ;128
_GUICtrlIpAddress_Set($IPAddress2, "255.255.255.0")
$IPAddress3 = _GUICtrlIpAddress_Create($Form1, 96, 224, 130, 21) ;176
_GUICtrlIpAddress_Set($IPAddress3, "192.168.0.0")
$IPAddress4 = _GUICtrlIpAddress_Create($Form1, 96, 264, 130, 21) ;224
_GUICtrlIpAddress_Set($IPAddress4, "192.168.0.1")
$IPAddress5 = _GUICtrlIpAddress_Create($Form1, 96, 304, 130, 21) ;264
_GUICtrlIpAddress_Set($IPAddress5, "192.168.0.2")

$Combo1 = GUICtrlCreateCombo("请下拉选择网卡", 25, 90, 280, 25, BitOR($CBS_DROPDOWNLIST, $CBS_AUTOHSCROLL))
$aaa = _ArrayToString($aArray)
;_ArrayDisplay($aArray)
GUICtrlSetData($Combo1, $aaa)

GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                        Case $Button1
                                                $ipset = StringStripWS(GUICtrlRead($Combo1),1)
                        ;$ipset = GUICtrlRead($Combo1)
                        $ip = _GUICtrlIpAddress_Get($IPAddress1)
                        $ym = _GUICtrlIpAddress_Get($IPAddress2)
                        $wg = _GUICtrlIpAddress_Get($IPAddress3)
                        $dns = _GUICtrlIpAddress_Get($IPAddress4)
                        $dns1 = _GUICtrlIpAddress_Get($IPAddress5)
                        
               
                                                $cba=RunWait(@ComSpec & " /c netsh interface ip set address """&$ipset&""" static "& " "& $ip & " " & $ym & " " & $wg & " " & "gwmetric=1", "",@SW_HIDE)
                                                $abc=RunWait(@ComSpec & " /c netsh interface ip set dns name = """&$ipset&"""  source = static addr = " & $dns & " register = PRIMARY", "", @SW_HIDE)
                                                $nba=RunWait(@ComSpec & " /c netsh interface ip add dns name = """&$ipset&"""  addr = " & $dns1 & " index=2", "", @SW_HIDE)
                                               
                                                If $cba = 0 Then
                                                MsgBox(64,"ok","IP设置成功",2)
                                                Else
                                                MsgBox(64,"ok","IP设置失败")
                                                EndIf
                                                If $abc = 0 Then
                                                MsgBox(64,"ok","主dns设置成功",2)
                                                Else
                                                MsgBox(64,"ok","主dns设置失败")
                                                EndIf
                                                If $nba = 0 Then
                                                MsgBox(64,"ok","备dns设置成功",2)
                                                Else
                                                MsgBox(64,"ok","备dns设置失败")
                                                EndIf


        EndSwitch
WEnd

Func GetAdapterProperty()
        Local $objShare
        Local $objEveryColl
        $objShare = ObjCreate("HNetCfg.HNetShare.1")
        If Not IsObj($objShare) Then Return
        $objEveryColl = $objShare.EnumEveryConnection
        If Not IsObj($objEveryColl) Then Return
        Local $objNetConn, $objShareCfg, $objNCProps, $str
        Local $aProps[0][5]
        For $objNetConn In $objEveryColl
                $objShareCfg = $objShare.INetSharingConfigurationForINetConnection($objNetConn)
                If IsObj($objShareCfg) Then
                        $objNCProps = $objShare.NetConnectionProps($objNetConn)
                        If IsObj($objNCProps) Then
                                ReDim $aProps[UBound($aProps) + 1][2]
                                $aProps[UBound($aProps) - 1][0] = $objNCProps.Name
                        EndIf
                EndIf
        Next
        Return $aProps
EndFunc   ;==>GetAdapterProperty
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-4-24 01:52 , Processed in 0.064578 second(s), 14 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表