|
楼主 |
发表于 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 |
|