楼主的代码还是有些问题的,我来帮你开放,让更多的人查阅。
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#Include <Date.au3>
;#Include <ACN_NET.au3>
#Include <WinAPI.au3>
#include <GuiStatusBar.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Include <Array.au3>
#Region ### START Koda GUI section ### Form=E:\作品\Form2-1.kxf
Global Const $NetworkAdapterInfo = _NetworkAdapterInfo() ;获得网卡信息.
Global Const $ScriptDir=@ScriptDir & '\'& "ip.ini"
Global Const $OSVersion= @OSVersion
MsgBox("1","sadf",$OSVersion)
;Global Const $ScriptDir1=@ScriptDir & '\'& "ip.ini")
Global $hIcons[2]
$Form2_1 = GUICreate("IP地址修改器", 709, 455, 271, 152)
$Group1 = GUICtrlCreateGroup("自动获取", 32, 8, 609, 441)
$Label1 = GUICtrlCreateLabel("网卡选择", 78, 32, 52, 17)
$Label2 = GUICtrlCreateLabel("计算机名", 78, 88, 52, 17)
$Input1 = GUICtrlCreateLabel("Input1", 152, 88, 329, 21)
$Label3 = GUICtrlCreateLabel("IP地址", 78, 144, 38, 17)
$Combo1 = GUICtrlCreateCombo("选择的网卡", 160, 24, 329, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL)) ;选择的网卡
GUICtrlSetResizing(-1, $GUI_DOCKHCENTER+$GUI_DOCKHEIGHT)
$Input2 = GUICtrlCreateLabel("IP地址", 152, 144, 169, 21)
$Label4 = GUICtrlCreateLabel("网关地址", 78, 192, 52, 17)
$Input3 = GUICtrlCreateLabel("网关", 152, 192, 169, 21)
$Label5 = GUICtrlCreateLabel("首选DNS", 78, 248, 51, 17)
$Input4 = GUICtrlCreateLabel("DNS", 152, 248, 169, 21)
$Label6 = GUICtrlCreateLabel("子网掩码", 336, 144, 52, 17)
$Input5 = GUICtrlCreateLabel("子网掩码", 392, 144, 169, 21)
$Label7 = GUICtrlCreateLabel("备用DNS", 336, 248, 51, 17)
$Input6 = GUICtrlCreateLabel("DNS", 392, 248, 169, 21)
$Button1 =GUICtrlCreateButton("执行", 208, 368, 113, 57)
$Button2 = GUICtrlCreateButton("退出", 368, 368, 113, 57)
GUICtrlCreateGroup("", -99, -99, 1, 1) ;在GUI上创建一个分组(Group)控件
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
$hStatus = _GUICtrlStatusBar_Create ($Form2_1) ;If using GUICtrlCreateMenu then use _GUICtrlStatusBar_Create after GUICtrlCreateMenu
Global $aParts[2] = [350, -1]
_GUICtrlStatusBar_SetParts ($hStatus, $aParts)
_GUICtrlStatusBar_SetText ($hStatus, " IP 地址修改器内部专用版本",0)
_GUICtrlStatusBar_SetText ($hStatus, " 酒店事业部", 1)
_GUICtrlStatusBar_SetIcon ($hStatus, 0, -19, "shell32.dll")
_GUICtrlStatusBar_SetIcon ($hStatus, 1, 221, "shell32.dll")
$hIcons[0] = _WinAPI_LoadShell32Icon (-19)
$hIcons[1] = _WinAPI_LoadShell32Icon (221)
_GUICtrlStatusBar_SetIcon ($hStatus, 0, $hIcons[0])
_GUICtrlStatusBar_SetIcon ($hStatus, 1, $hIcons[1])
;_ArrayDisplay($NetworkAdapterInfo)
;保存IP地址和往输入框里填写固定IP。
For $i=1 To $NetworkAdapterInfo[0][0]
GUICtrlSetData($Combo1,$NetworkAdapterInfo[1][3],$NetworkAdapterInfo[1][3])
;获取IP、子网掩码、网关并保存在IP.INI文件里,并将要改的IP地址显示在输入框里。
If $NetworkAdapterInfo[$i][0] = 0 Then
GUICtrlSetData($Combo1,"没有找到可用的网卡信息^_^")
Else
If $NetworkAdapterInfo[1][6] = True Then
IniWrite ( $ScriptDir, "DHCP", "dhcp值", "True")
GUICtrlSetData($Input1,@ComputerName)
GUICtrlSetData($Input2,"192.168.1.82")
GUICtrlSetData($Input3,"192.168.1.1")
GUICtrlSetData($Input4,"202.106.0.20")
GUICtrlSetData($Input5,"255.255.255.0")
GUICtrlSetData($Input6,"210.82.5.1")
MsgBox("1","wert","DHCP状态已保存")
EndIf
If $NetworkAdapterInfo[1][6] = False then
IniWrite ( $ScriptDir, "DHCP", "dhcp值", "False")
IniWrite ( $ScriptDir, $NetworkAdapterInfo[1][3], "ip地址", $NetworkAdapterInfo[1][7])
IniWrite ( $ScriptDir, $NetworkAdapterInfo[1][3], "子网掩码",$NetworkAdapterInfo[1][8])
IniWrite ( $ScriptDir, $NetworkAdapterInfo[1][3], "网关地址",$NetworkAdapterInfo[1][9])
IniWrite ( $ScriptDir, $NetworkAdapterInfo[1][3], "首选DNS",$NetworkAdapterInfo[1][10])
IniWrite ( $ScriptDir, $NetworkAdapterInfo[1][3], "备用DNS",$NetworkAdapterInfo[1][11])
GUICtrlSetData($Input1,@ComputerName)
GUICtrlSetData($Input2,"192.168.1.82")
GUICtrlSetData($Input3,"192.168.1.1")
GUICtrlSetData($Input4,"202.106.0.20")
GUICtrlSetData($Input5,"255.255.255.0")
GUICtrlSetData($Input6,"210.82.5.1")
MsgBox("1","wert","ip地址:"&$NetworkAdapterInfo[1][7]&@CRLF&"子网掩码:"&$NetworkAdapterInfo[1][8]&@CRLF&"网关地址:"&$NetworkAdapterInfo[1][9]&@CRLF&"首选DNS:"&$NetworkAdapterInfo[1][10]&@CRLF&"备用DNS:"&$NetworkAdapterInfo[1][11]&@CRLF&"都已保存")
EndIf
EndIf
Next
;捕获IP和修改IP,和恢复原来的IP地址。
While 1
$nMsg = GUIGetMsg() ;捕获窗口消息
Switch $nMsg
Case $GUI_EVENT_CLOSE ;对话框(窗口)正被关闭(相关按钮被点击或系统菜单项被选中).
Exit
Case $Button1 ;更改IP地址
If GUICtrlRead($Combo1) = "本地连接" Then
$ConName = $NetworkAdapterInfo[1][3]
MsgBox("1","a",$ConName)
$IpADD = GUICtrlRead($Input2)
$GateWay = GUICtrlRead($Input3)
$ConDNS2 = GUICtrlRead($Input6)
$SubMask = GUICtrlRead($Input5)
$ConDNS1 = GUICtrlRead($Input4)
MsgBox("1","a","")
MsgBox("1","wert","ip地址:"&$IpADD&@CRLF&"子网掩码:"&$SubMask&@CRLF&"网关地址:"&$GateWay&@CRLF&"首选DNS:"&$ConDNS1&@CRLF&"备用DNS:"&$ConDNS2&@CRLF&"都已更改")
If $OSVersion = "WIN_XP" Then
_CMD_SetLocalIP_XP($ConName,$IpADD,$SubMask,$GateWay,$ConDNS1,$ConDNS2)
EndIf
If $OSVersion = "WIN_7" Then
_CMD_SetLocalIP_WIN7($ConName,$IpADD,$SubMask,$GateWay,$ConDNS1,$ConDNS2)
EndIf
Exit
EndIf
Case $Button2
If GUICtrlRead($Combo1) = "本地连接" Then
MsgBox(1,"",IniRead($ScriptDir, "DHCP", "dhcp值", "NotFound"))
If IniRead($ScriptDir, "DHCP", "dhcp值", " ") = "True" Then
MsgBox("1","ss","asdfasdfasdfasdfasfd")
_DHCP_IP_SetLocalIP()
_DHCP_DNS_SetLocalIP()
EndIf
If IniRead($ScriptDir, "DHCP", "dhcp值", " ") = "False" Then
GUICtrlSetData($Input1,@ComputerName) ;修改指定控件的数据.
GUICtrlSetData($Input2,IniRead($ScriptDir, "本地连接", "ip地址", "NotFound"))
GUICtrlSetData($Input3,IniRead($ScriptDir, "本地连接", "网关地址", "NotFound"))
GUICtrlSetData($Input4,IniRead($ScriptDir, "本地连接", "首选DNS", "NotFound"))
GUICtrlSetData($Input5,IniRead($ScriptDir, "本地连接", "子网掩码", "NotFound"))
GUICtrlSetData($Input6,IniRead($ScriptDir, "本地连接", "备用DNS", "NotFound"))
$ConName = $NetworkAdapterInfo[1][3]
$IpADD = GUICtrlRead($Input2)
$GateWay = GUICtrlRead($Input3)
$ConDNS1 = GUICtrlRead($Input4)
$SubMask = GUICtrlRead($Input5)
$ConDNS2 = GUICtrlRead($Input6)
MsgBox("1","sss","asdfasdfasdfasdfasfd")
MsgBox("1","wert","ip地址:"&$IpADD&@CRLF&"子网掩码:"&$SubMask&@CRLF&"网关地址:"&$GateWay&@CRLF&"首选DNS:"&$ConDNS1&@CRLF&"备用DNS:"&$ConDNS2&@CRLF&"都已还原初始状态")
If $OSVersion = "WIN_XP" Then
_CMD_SetLocalIP_XP($ConName,$IpADD,$SubMask,$GateWay,$ConDNS1,$ConDNS2)
EndIf
If $OSVersion = "WIN_7" Then
_CMD_SetLocalIP_WIN7($ConName,$IpADD,$SubMask,$GateWay,$ConDNS1,$ConDNS2)
EndIf
;_CMD_SetLocalIP($ConName,$IpADD,$SubMask,$GateWay,$ConDNS1,$ConDNS2)
Exit
EndIf
EndIf
EndSwitch
WEnd
Func _NetworkAdapterInfo()
Local $colItems1 = ""
Local $objWMIService
Local $NetworkAdapterID = 0
Local $NetworkAdapterName = ""
Local $NetworkAdapterGateway = ""
Local $NetworkAdapterHostName = ""
Local $NetworkAdapterIPaddress = ""
Local $NetworkAdapterDNS1 = ""
Local $NetworkAdapterDNS2 = ""
Local $NetworkAdapterSubnet = ""
Local $NetworkAdapterMAC = ""
Local $NetworkAdapterNetConnectionID = ""
Local $NetworkAdapterNetConnectionStatus = ""
Local $NetworkAdapterInfo[10][12] ;最高10块网卡.
$NetworkAdapterInfo[0][0] = 0
$objWMIService = ObjGet("winmgmts:\\localhost\root\CIMV2")
$colItems1 = $objWMIService.ExecQuery('SELECT * FROM Win32_NetworkAdapter WHERE NetConnectionStatus >0 ', "WQL", 0x30)
If IsObj($colItems1) Then
For $objItem In $colItems1
$NetworkAdapterName = $objItem.Description
If $NetworkAdapterName="" Then ContinueLoop
If StringInStr ($NetworkAdapterName,"vmware")=True Then ContinueLoop
$NetworkAdapterNetConnectionStatus = $objItem.NetConnectionStatus
$NetworkAdapterNetConnectionID = $objItem.NetConnectionID
If StringInStr ($NetworkAdapterNetConnectionID,"无线")=True Then ContinueLoop
$NetworkAdapterIndex = $objItem.Index
$NetworkAdapterMAC = $objItem.MACAddress
$NetworkAdapterID += 1
$NetworkAdapterInfo[0][0] = $NetworkAdapterID
$NetworkAdapterInfo[$NetworkAdapterID][0] = $NetworkAdapterID
$NetworkAdapterInfo[$NetworkAdapterID][1] = $NetworkAdapterName
$NetworkAdapterInfo[$NetworkAdapterID][2] = $NetworkAdapterNetConnectionStatus ;反回的值是2表示在线,7表示不在线。
$NetworkAdapterInfo[$NetworkAdapterID][3] = $NetworkAdapterNetConnectionID
MsgBox("1","3",$NetworkAdapterInfo[$NetworkAdapterID][3])
$NetworkAdapterInfo[$NetworkAdapterID][4] = $NetworkAdapterMAC
$NetworkAdapterInfo[$NetworkAdapterID][5] = $NetworkAdapterIndex
Local $colItems2 = $objWMIService.ExecQuery('SELECT * FROM Win32_NetworkAdapterConfiguration WHERE Index = "'& $NetworkAdapterIndex &'" ', "WQL", 0x30)
If IsObj($colItems2) Then
For $objItem2 In $colItems2
$NetworkAdapterIPaddress = $objItem2.IPAddress(0)
$NetworkAdapterDHCPEnabled = $objItem2.DHCPEnabled
$NetworkAdapterIPSubnet = $objItem2.IPSubnet(0)
$NetworkAdapterDefaultIPGateway = $objItem2.DefaultIPGateway(0)
$NetworkAdapterDNS1 = $objItem2.DNSServerSearchOrder(0)
$NetworkAdapterInfo[$NetworkAdapterID][6] = $NetworkAdapterDHCPEnabled
$NetworkAdapterInfo[$NetworkAdapterID][7] = $NetworkAdapterIPaddress
$NetworkAdapterInfo[$NetworkAdapterID][8] = $NetworkAdapterIPSubnet
$NetworkAdapterInfo[$NetworkAdapterID][9] = $NetworkAdapterDefaultIPGateway
$NetworkAdapterInfo[$NetworkAdapterID][10] = $NetworkAdapterDNS1
If UBound($objItem2.DNSServerSearchOrder)>1 Then
$NetworkAdapterDNS2 = $objItem2.DNSServerSearchOrder(1)
$NetworkAdapterInfo[$NetworkAdapterID][11] = $NetworkAdapterDNS2
EndIf
Next
EndIf
Next
Else
Return $NetworkAdapterInfo
EndIf
Return $NetworkAdapterInfo
_ArrayDisplay($NetworkAdapterInfo)
EndFunc ;==>_NetworkAdapterInfo
Func _CMD_SetLocalIP_WIN7($ConName, $IpADD, $SubMask, $GateWay, $ConDNS1,$ConDNS2)
If $SubMask <> "" Then $SubMask = "255.255.255.0"
If $ConName <> "" And $IpADD <> "" Then
RunWait(@ComSpec & ' /C netsh -c interface ip set address ' & '"' & $ConName & '"' & ' static ' & $IpADD & " " & $SubMask & " " & $GateWay, "", @SW_HIDE)
EndIf
If $ConDNS1 <> "" Then
RunWait(@ComSpec & ' /C netsh -c interface ip set dns ' & '"' & $ConName & '"' & ' static ' & $ConDNS1 & ' primary validate=no', "", @SW_HIDE)
EndIf
If $ConDNS2 <> "" Then
RunWait(@ComSpec & ' /C netsh -c interface ip add dns ' & '"' & $ConName & '" ' & $ConDNS2 & ' validate=no', "", @SW_HIDE)
EndIf
EndFunc ;==>_CMD_SetLocalIP
Func _CMD_SetLocalIP_XP($ConName, $IpADD, $SubMask, $GateWay, $ConDNS1,$ConDNS2)
If $SubMask <> "" Then $SubMask = "255.255.255.0"
If $ConName <> "" And $IpADD <> "" Then
RunWait(@ComSpec & ' /C netsh interface ip set address ' & '"' & $ConName & '"' & ' static ' & $IpADD & " " & $SubMask & " " & $GateWay & " " & ' none ',"", @SW_HIDE)
EndIf
If $ConDNS1 <> "" Then
RunWait(@ComSpec & ' /C netsh interface ip set dns ' & '"' & $ConName & '"' & ' static ' & $ConDNS1 & ' primary', "", @SW_HIDE)
EndIf
If $ConDNS2 <> "" Then
RunWait(@ComSpec & ' /C netsh interface ip add dns ' & '"' & $ConName & '" ' & $ConDNS2,"", @SW_HIDE)
EndIf
EndFunc ;==>_CMD_SetLocalIP
Func _DHCP_IP_SetLocalIP()
RunWait(@ComSpec & ' /C netsh interface ip set address ' & '"' & $NetworkAdapterInfo[1][3] & '"' & ' source=dhcp ', "", @SW_HIDE)
EndFunc
Func _DHCP_DNS_SetLocalIP()
RunWait(@ComSpec & ' /C netsh interface ip set dns ' & '"' & $NetworkAdapterInfo[1][3] & '"' & ' source=dhcp ', "", @SW_HIDE)
EndFunc
|