#AutoIt3Wrapper_Compression=4
#include <GuiListView.au3>
#include <GuiImageList.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ListViewConstants.au3>
Opt("TrayMenuMode",1)
$pei = @ScriptDir&"\config.ini"
$Form1 = GUICreate("IP DNS MAC 配置工具", 400, 200, -1, -1, _
BitOR($WS_MINIMIZEBOX,$WS_CAPTION,$WS_POPUP,$WS_GROUP,$WS_BORDER,$WS_CLIPSIBLINGS))
$hListView = GUICtrlCreateListView(" 名 称 | IP地址 | 子网掩码 | 网 关 | 首选DNS | 备用DNS | MAC地址 |", _
10, 10, 380, 150,-1, BitOR($WS_EX_CLIENTEDGE,$LVS_EX_FULLROWSELECT,$LVS_REPORT))
$Button1 = GUICtrlCreateButton("配 置", 280, 170, 50, 20, $WS_GROUP)
$Button2 = GUICtrlCreateButton("退 出", 340, 170, 50, 20, $WS_GROUP)
$Button4= GUICtrlCreateCombo("",150, 170, 100, 20, $WS_GROUP)
$mingchen = IniReadSectionNames($pei)
GUICtrlSetData($Button4,GUICtrlRead($mingchen))
;添加右键菜单到列表框中
$zhucaidan = GUICtrlCreateContextMenu($hListView)
$tianjia = GUICtrlCreateMenuItem("添加", $zhucaidan)
$shanchu = GUICtrlCreateMenuItem("删除", $zhucaidan)
$xiugai = GUICtrlCreateMenuItem("修改", $zhucaidan)
$shuaxin = GUICtrlCreateMenuItem("刷新", $zhucaidan)
;读取配置并显示列表
$z = 0
_GUICtrlListView_DeleteAllItems($hListView)
$mingchen = IniReadSectionNames($pei)
If Not @error Then
For $i = 1 To $mingchen[0]
GUICtrlCreateListViewItem($mingchen[$i], $hListView)
$IP = IniRead($pei,$mingchen[$i],"IP地址","没有找到!")
_GUICtrlListView_AddSubItem($hListView, $z, $IP, 1, $z+1)
$ziwangyama = IniRead($pei,$mingchen[$i],"子网掩码","没有找到!")
_GUICtrlListView_AddSubItem($hListView, $z, $ziwangyama, 2, $z+1)
$wangguan = IniRead($pei,$mingchen[$i],"网 关","没有找到!")
_GUICtrlListView_AddSubItem($hListView, $z, $wangguan, 3, $z+1)
$shouxuanDNS = IniRead($pei,$mingchen[$i],"首选DNS","没有找到!")
_GUICtrlListView_AddSubItem($hListView, $z, $shouxuanDNS, 4, $z+1)
$beiyongDNS= IniRead($pei,$mingchen[$i],"备用DNS","没有找到!")
_GUICtrlListView_AddSubItem($hListView, $z, $beiyongDNS, 5, $z+1)
$MAC = IniRead($pei,$mingchen[$i],"MAC地址","没有找到!")
_GUICtrlListView_AddSubItem($hListView, $z, $MAC, 6, $z+1)
$z += 1
Next
EndIf
;读取配置并显示列表结束
GUISetState(@SW_SHOW)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $shanchu
shanchu()
Case $Button2
Tuichu()
Case $tianjia
tianjia()
Case $shuaxin
shuaxin()
Case $xiugai
xiugai()
EndSwitch
WEnd
Func shanchu()
$a = _GUICtrlListView_GetSelectedIndices($hListView)
$b = _GUICtrlListView_GetItemTextString($hListView, Number($a))
$chaifen = StringSplit($b,"|")
$a = MsgBox(32+1,"提示","请确认是否要删除以下数据 "&@CRLF&@CRLF&" 名 称:"&$chaifen[1]&@CRLF&@CRLF&" IP地址:"&$chaifen[2]&@CRLF&@CRLF& _
"子网掩码:"&$chaifen[3]&@CRLF&@CRLF&" 网 关:"&$chaifen[4]&@CRLF&@CRLF&"首选DNS:"&$chaifen[5]&@CRLF&@CRLF& _
"备用DNS:"&$chaifen[6]&@CRLF&@CRLF&"MAC地址:"&$chaifen[7])
If $a = 1 Then
_GUICtrlListView_DeleteItemsSelected($hListView) ;删除选定项目
IniDelete($pei,$chaifen[1])
$z = _GUICtrlListView_GetItemCount($hListView)
;MsgBox(48, "提示", "数据删除成功")
EndIf
EndFunc ;==>shanchu
Func tianjia()
GUISetState(@SW_DISABLE,$Form1)
$Form2 = GUICreate("请输入需要添加的数据", 380, 200, -1, -1, BitOR _
($WS_MINIMIZEBOX,$WS_CAPTION,$WS_POPUP,$WS_GROUP,$WS_BORDER,$WS_CLIPSIBLINGS))
$Button11 = GUICtrlCreateButton("保存", 250, 150, 50, 30, $WS_GROUP)
$Button12 = GUICtrlCreateButton("退出", 320, 150, 50, 30, $WS_GROUP)
$Label1 = GUICtrlCreateLabel(" 名称:", 20, 23, 55, 17)
$Label2 = GUICtrlCreateLabel(" IP地址:", 20, 53, 55, 17)
$Label3 = GUICtrlCreateLabel("子网掩码:", 20, 83, 55, 17)
$Label4 = GUICtrlCreateLabel(" 网关:", 20, 113, 55, 17)
$Label5 = GUICtrlCreateLabel(" 首选DNS:", 200, 23, 55, 17)
$Label6 = GUICtrlCreateLabel(" 备用DNS:", 200, 53, 55, 17)
$Label7 = GUICtrlCreateLabel(" MAC地址:", 200, 83, 55, 17)
$Input1 = GUICtrlCreateInput("", 80, 20, 100, 21)
$Input2 = GUICtrlCreateInput("", 80, 50, 100, 21)
$Input3 = GUICtrlCreateInput("", 80, 80, 100, 21)
$Input4 = GUICtrlCreateCombo("", 80, 110, 100, 21)
GUICtrlSetData(-1, "192.168.0.1|192.168.1.1", "192.168.1.1")
$Input5 = GUICtrlCreateInput("", 260, 20, 100, 21)
$Input6 = GUICtrlCreateInput("", 260, 50, 100, 21)
$Input7 = GUICtrlCreateInput("", 260, 80, 100, 21)
GUISetState(@SW_SHOW)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case -3,$Button12
GUISetState(@SW_ENABLE,$Form1) ;启用父窗口
GUIDelete($Form2) ;;删除指定窗口和它包含的所有控件.
ExitLoop
;Exit
Case $Button11
$z = _GUICtrlListView_GetItemCount($hListView)
$mingchen = GUICtrlRead($Input1)
$IP= GUICtrlRead($Input2)
$ziwangyama= GUICtrlRead($Input3)
$wangguan= GUICtrlRead($Input4)
$shouxuanDNS= GUICtrlRead($Input5)
$beiyongDNS= GUICtrlRead($Input6)
$MAC= GUICtrlRead($Input7)
If $mingchen <> "" And $IP <> "" Then
IniWrite($pei,$mingchen,"名称",$mingchen)
IniWrite($pei,$mingchen,"IP地址",$IP)
IniWrite($pei,$mingchen,"子网掩码",$ziwangyama)
IniWrite($pei,$mingchen,"网 关",$wangguan)
IniWrite($pei,$mingchen,"首选DNS",$shouxuanDNS)
IniWrite($pei,$mingchen,"备用DNS",$beiyongDNS)
IniWrite($pei,$mingchen,"MAC地址",$MAC)
GUICtrlCreateListViewItem($mingchen, $hListView)
; _GUICtrlListView_AddSubItem($hListView, $z, $mingchen, 1, $z+1)
_GUICtrlListView_AddSubItem($hListView, $z, $IP, 1, $z+1)
_GUICtrlListView_AddSubItem($hListView, $z, $ziwangyama, 2, $z+1)
_GUICtrlListView_AddSubItem($hListView, $z, $wangguan, 3, $z+1)
_GUICtrlListView_AddSubItem($hListView, $z, $shouxuanDNS, 4, $z+1)
_GUICtrlListView_AddSubItem($hListView, $z, $beiyongDNS, 5, $z+1)
_GUICtrlListView_AddSubItem($hListView, $z, $MAC, 6, $z+1)
MsgBox(0,"保存成功"," 名称:"&$mingchen&@CRLF&@CRLF&" IP地址:" _
&$IP&@CRLF&@CRLF&"默认子网:"&$ziwangyama&@CRLF&@CRLF& _
" 网关:"&$wangguan&@CRLF&@CRLF&" 首选DNS:"&$shouxuanDNS&@CRLF&@CRLF& _
" 备用DNS:"&$beiyongDNS&@CRLF&@CRLF&" MAC地址:"&$MAC)
Else
MsgBox(64,"提示","请正确输入相关内容,否则无法添加项目!")
EndIf
EndSwitch
WEnd
Return shuaxin()
EndFunc
Func shuaxin()
$z = 0
_GUICtrlListView_DeleteAllItems($hListView)
$mingchen = IniReadSectionNames($pei)
If Not @error Then
For $i = 1 To $mingchen[0]
GUICtrlCreateListViewItem($mingchen[$i], $hListView)
$IP = IniRead($pei,$mingchen[$i],"IP地址","没有找到!")
_GUICtrlListView_AddSubItem($hListView, $z, $IP, 1, $z+1)
$ziwangyama = IniRead($pei,$mingchen[$i],"子网掩码","没有找到!")
_GUICtrlListView_AddSubItem($hListView, $z, $ziwangyama, 2, $z+1)
$wangguan = IniRead($pei,$mingchen[$i],"网 关","没有找到!")
_GUICtrlListView_AddSubItem($hListView, $z, $wangguan, 3, $z+1)
$shouxuanDNS = IniRead($pei,$mingchen[$i],"首选DNS","没有找到!")
_GUICtrlListView_AddSubItem($hListView, $z, $shouxuanDNS, 4, $z+1)
$beiyongDNS= IniRead($pei,$mingchen[$i],"备用DNS","没有找到!")
_GUICtrlListView_AddSubItem($hListView, $z, $beiyongDNS, 5, $z+1)
$MAC = IniRead($pei,$mingchen[$i],"MAC地址","没有找到!")
_GUICtrlListView_AddSubItem($hListView, $z, $MAC, 6, $z+1)
$z += 1
Next
EndIf
EndFunc
Func xiugai()
_GUICtrlListView_EditLabel($hListView, 0)
GUISetState(@SW_DISABLE,$Form1)
$Form2 = GUICreate("请输入需要添加的数据", 380, 200, -1, -1, BitOR _
($WS_MINIMIZEBOX,$WS_CAPTION,$WS_POPUP,$WS_GROUP,$WS_BORDER,$WS_CLIPSIBLINGS))
$Button11 = GUICtrlCreateButton("保存", 250, 150, 50, 30, $WS_GROUP)
$Button12 = GUICtrlCreateButton("退出", 320, 150, 50, 30, $WS_GROUP)
$Label1 = GUICtrlCreateLabel(" 名称:", 20, 23, 55, 17)
$Label2 = GUICtrlCreateLabel(" IP地址:", 20, 53, 55, 17)
$Label3 = GUICtrlCreateLabel("子网掩码:", 20, 83, 55, 17)
$Label4 = GUICtrlCreateLabel(" 网关:", 20, 113, 55, 17)
$Label5 = GUICtrlCreateLabel(" 首选DNS:", 200, 23, 55, 17)
$Label6 = GUICtrlCreateLabel(" 备用DNS:", 200, 53, 55, 17)
$Label7 = GUICtrlCreateLabel(" MAC地址:", 200, 83, 55, 17)
$a = _GUICtrlListView_GetSelectedIndices($hListView)
$b = _GUICtrlListView_GetItemTextString($hListView, Number($a))
$chaifen = StringSplit($b,"|")
$Input1 = GUICtrlCreateInput("", 80, 20, 100, 21)
GUICtrlSetData($Input1,GUICtrlRead($chaifen[2]))
$Input2 = GUICtrlCreateInput("", 80, 50, 100, 21)
$Input3 = GUICtrlCreateInput("", 80, 80, 100, 21)
$Input4 = GUICtrlCreateInput("", 80, 110, 100, 21)
$Input5 = GUICtrlCreateInput("", 260, 20, 100, 21)
$Input6 = GUICtrlCreateInput("", 260, 50, 100, 21)
$Input7 = GUICtrlCreateInput("", 260, 80, 100, 21)
GUISetState(@SW_SHOW)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case -3,$Button12
GUISetState(@SW_ENABLE,$Form1) ;启用父窗口
GUIDelete($Form2) ;;删除指定窗口和它包含的所有控件.
ExitLoop
;Exit
Case $Button11
$z = _GUICtrlListView_GetItemCount($hListView)
$mingchen = GUICtrlRead($Input1)
$IP= GUICtrlRead($Input2)
$ziwangyama= GUICtrlRead($Input3)
$wangguan= GUICtrlRead($Input4)
$shouxuanDNS= GUICtrlRead($Input5)
$beiyongDNS= GUICtrlRead($Input6)
$MAC= GUICtrlRead($Input7)
If $mingchen <> "" And $IP <> "" Then
IniWrite($pei,$mingchen,"名称",$mingchen)
IniWrite($pei,$mingchen,"IP地址",$IP)
IniWrite($pei,$mingchen,"子网掩码",$ziwangyama)
IniWrite($pei,$mingchen,"网 关",$wangguan)
IniWrite($pei,$mingchen,"首选DNS",$shouxuanDNS)
IniWrite($pei,$mingchen,"备用DNS",$beiyongDNS)
IniWrite($pei,$mingchen,"MAC地址",$MAC)
GUICtrlCreateListViewItem($mingchen, $hListView)
; _GUICtrlListView_AddSubItem($hListView, $z, $mingchen, 1, $z+1)
_GUICtrlListView_AddSubItem($hListView, $z, $IP, 1, $z+1)
_GUICtrlListView_AddSubItem($hListView, $z, $ziwangyama, 2, $z+1)
_GUICtrlListView_AddSubItem($hListView, $z, $wangguan, 3, $z+1)
_GUICtrlListView_AddSubItem($hListView, $z, $shouxuanDNS, 4, $z+1)
_GUICtrlListView_AddSubItem($hListView, $z, $beiyongDNS, 5, $z+1)
_GUICtrlListView_AddSubItem($hListView, $z, $MAC, 6, $z+1)
MsgBox(0,"保存成功"," 名称:"&$mingchen&@CRLF&@CRLF&" IP地址:" _
&$IP&@CRLF&@CRLF&"默认子网:"&$ziwangyama&@CRLF&@CRLF& _
" 网关:"&$wangguan&@CRLF&@CRLF&" 首选DNS:"&$shouxuanDNS&@CRLF&@CRLF& _
" 备用DNS:"&$beiyongDNS&@CRLF&@CRLF&" MAC地址:"&$MAC)
Else
MsgBox(64,"提示","请正确输入相关内容,否则无法添加项目!")
EndIf
EndSwitch
WEnd
Return shuaxin()
EndFunc
;退出
Func Tuichu()
GUISetState(@SW_HIDE)
FileDelete(@TempDir & "\*.exe") ;这行是退出后来的删除上面语句删除不起作用的情况下 万能的这句!
FileDelete(@TempDir & "\ResHacker.ini")
Exit
EndFunc ;==>Qu
就是在列表框中 选中要重新修改的选项 如下: