原因:网上找一个备份交换机的软件,竟然要钱,,晕晕。。还不如自己写一个。
通过tftp备份交换机,支持cisco huawei h3c,只完成基本功能,界面之类的大家可以扩展 ,命令里支持正则表达式。效果如图
;by onepc 153785587
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiIPAddress.au3>
#include <StaticConstants.au3>
#include <TreeViewConstants.au3>
#include <WindowsConstants.au3>
#include <GuiTreeView.au3>
#include <Array.au3>
#Include <GuiListView.au3>
#include <GuiMenu.au3>
Opt("GUIOnEventMode", 1)
#Region ### START Koda GUI section ### Form=f:\myziliao\2011-8-3\au3\telnet\form1.kxf
;HKEY_CURRENT_USER\Software\Cisco Systems Inc.\Cisco TFTP Server\1.1\Options TFTPRootDirectory tftp保存的路径 LogFileName日志名称(TFTPServer.log)需要带名称 reg_sz
;Global $switchname="onepc"
Global $hTreeView,$iContext,$hContext,$menudel,$menuexit,$ArrItem[256],$k=0 ;设置数据保存treeview的item句柄 $k表示数组的数量
;Global $k1 = 0,$ArrTree[256]
Global $cfg = @ScriptDir & "\cfg.ini"
;Global $maincfg = @ScriptDir & "\maincfg.ini"
Global $swcfg = @ScriptDir & "\Switch\"
Local $iStyle = BitOR($TVS_EDITLABELS, $TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS)
;$ArrTree[0] = $k1 ;根节点
$ArrItem[0]= $k ;根的子节点
;If Not FileExists($maincfg) Then
; _CreateIniCfg($maincfg,1)
;EndIf
;_LoadINI($maincfg) ;读取tftp user pass
$Form1 = GUICreate("BackSwitch", 513, 341, -1, -1,-1,$WS_EX_TOPMOST)
GUISetOnEvent($GUI_EVENT_CLOSE, "GuiEvent")
$hTreeView = GUICtrlCreateTreeView(8, 8, 161, 321,$iStyle, $WS_EX_CLIENTEDGE)
GUICtrlSetOnEvent(-1, "GuiEvent")
$Group1 = GUICtrlCreateGroup("", 176, 56, 329, 89)
$Label1 = GUICtrlCreateLabel("Switchip", 192, 82, 54, 17)
$Input1 = GUICtrlCreateInput("", 248, 78, 241, 21)
$Input6 = GUICtrlCreateInput("", 247, 110, 113, 21)
$Button1 = GUICtrlCreateButton("Backup", 367, 108, 59, 25)
GUICtrlSetOnEvent(-1, "GuiEvent")
$Button3 = GUICtrlCreateButton("BackAll", 432, 108, 59, 25)
GUICtrlSetOnEvent(-1, "GuiEvent")
$Label2 = GUICtrlCreateLabel("SwitchM", 192, 112, 53, 17)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group2 = GUICtrlCreateGroup("Add Switch", 176, 152, 329, 177)
$Label3 = GUICtrlCreateLabel("Switchip", 200, 232, 52, 17)
$Label4 = GUICtrlCreateLabel("SwitchName", 192, 200, 64, 17)
$Button2 = GUICtrlCreateButton("AddSwitch", 416, 296, 75, 25)
GUICtrlSetOnEvent(-1, "GuiEvent")
$Label5 = GUICtrlCreateLabel("Address", 200, 176, 42, 17)
$Input4 = GUICtrlCreateInput("", 272, 168, 217, 21)
$Label6 = GUICtrlCreateLabel("SwitchMode", 192, 264, 63, 17)
$Input5 = GUICtrlCreateInput("", 272, 232, 217, 21)
$Combo1 = GUICtrlCreateCombo("", 272, 264, 137, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))
GUICtrlSetData(-1, "Cisco|Huawei|H3C", "Cisco")
$Input2 = GUICtrlCreateInput("", 272, 200, 217, 21)
$Input3 = GUICtrlCreateInput("", 216, 294, 73, 21)
$Input7 = GUICtrlCreateInput("", 328, 294, 73, 21)
$Label7 = GUICtrlCreateLabel("U", 200, 296, 12, 17)
$Label8 = GUICtrlCreateLabel("P", 304, 296, 11, 17)
$Checkbox1 = GUICtrlCreateCheckbox("Privilege", 424, 264, 73, 17)
GUICtrlSetState($Checkbox1,$GUI_CHECKED)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group3 = GUICtrlCreateGroup("", 176, 2, 329, 49)
$Button4 = GUICtrlCreateButton("Start", 336, 16, 43, 25)
GUICtrlSetOnEvent(-1, "GuiEvent")
$Button5 = GUICtrlCreateButton("Stop", 384, 16, 43, 25)
GUICtrlSetOnEvent(-1, "GuiEvent")
$Button6 = GUICtrlCreateButton("BackupPath", 432, 16, 67, 25)
GUICtrlSetOnEvent(-1, "GuiEvent")
$Input8 = GUICtrlCreateInput(@IPAddress1, 224, 18, 105, 21)
$Label9 = GUICtrlCreateLabel("TFTP", 192, 21, 31, 17)
GUICtrlCreateGroup("", -99, -99, 1, 1)
If Not FileExists($cfg) Then
_CreateIniCfg($swcfg & "192.168.15.196" &".txt",11,"root","wen")
_CreateIniCfg($cfg,2,"","","机房大楼", "Switch196","192.168.15.196","Cisco")
EndIf
_InitTreeView($hTreeView,$cfg)
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
;$Menu = _GUICtrlMenu_CreatePopup()
;_GUICtrlMenu_InsertMenuItem($Menu, 0, "删除", $menudel)
;_GUICtrlMenu_InsertMenuItem($Menu, 1, "退出", $menuexit)
$iContext = GUICtrlCreateContextMenu(GUICtrlCreateDummy())
$hContext = GUICtrlGetHandle($iContext)
$menudel = GUICtrlCreateMenuItem("删除", $iContext)
$menuexit = GUICtrlCreateMenuItem("退出", $iContext)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
Sleep(100)
WEnd
Func GuiEvent()
Switch @GUI_CtrlId
Case $GUI_EVENT_CLOSE
_StopTFTP() ;关闭ftp
Exit
Case $Button1 ;backup
_ExistsTFTP()
_BackupSwitch(GUICtrlRead($Input1),GUICtrlRead($Input6),$swcfg & GUICtrlRead($Input1) & ".txt")
Case $Button2 ;addswitch
If GUICtrlRead($Input4)="" Or GUICtrlRead($Input2)="" Or GUICtrlRead($Input5)="" Then
MsgBox(0,"提示","请全部填写")
Return
EndIf
Switch GUICtrlRead($Combo1)
Case "Cisco"
_CreateIniCfg($swcfg & GUICtrlRead($Input5) &".txt",11,GUICtrlRead($Input3),GUICtrlRead($Input7))
_CreateIniCfg($cfg,2,"","",GUICtrlRead($Input4), GUICtrlRead($Input2), GUICtrlRead($Input5),GUICtrlRead($Combo1));_CreateIniCfg($path,$main = 0,$user="",$pass="",$swadd="",$swname="",$swi="",$swmo="")
Case "Huawei"
_CreateIniCfg($swcfg & GUICtrlRead($Input5) &".txt",12,GUICtrlRead($Input3),GUICtrlRead($Input7))
_CreateIniCfg($cfg,2,"","",GUICtrlRead($Input4), GUICtrlRead($Input2), GUICtrlRead($Input5),GUICtrlRead($Combo1))
Case "H3C"
_CreateIniCfg($swcfg & GUICtrlRead($Input5) &".txt",13,GUICtrlRead($Input3),GUICtrlRead($Input7))
_CreateIniCfg($cfg,2,"","",GUICtrlRead($Input4), GUICtrlRead($Input2), GUICtrlRead($Input5),GUICtrlRead($Combo1))
EndSwitch
_InitTreeView($hTreeView,$cfg)
Case $Button3
;$xxx = _MySimpleEncry( _Base64Encode("onepc"))
;MsgBox(0,"",$xxx )
;MsgBox(0,"",BinaryToString(_Base64Decode(_MySimpleDeEncry($xxx))) )
Case $Button4 ;starttftp
_StartTFTP()
Case $Button5
_StopTFTP()
Case $Button6 ;backuppath
_SetBackupPath()
EndSwitch
EndFunc
Func _InitTreeView($handTree,$path) ;初始化
Local $i,$SectionName,$SecValue,$j,$item
_GUICtrlTreeView_DeleteAll($handTree)
_GUICtrlTreeView_BeginUpdate($handTree)
$SectionName = IniReadSectionNames($path) ;所以字段名
If @error Then
MsgBox(4096, "", "错误, 读取INI文件失败.")
exit
Else
For $i = 1 To $SectionName[0]
;$k1 = $k1+1
;If $k1 <255 Then ;;;;
$item = _GUICtrlTreeView_Add($handTree, 0, $SectionName[$i])
$SecValue = IniReadSection ($path, $SectionName[$i])
For $j=1 To $SecValue[0][0]
$k = $k+1
If $k<255 Then ;不能超过256个
$ArrItem[$k] = _GUICtrlTreeView_AddChild($handTree, $item,$SecValue[$j][0] )
EndIf
Next
;EndIf ;;;;;;
Next
$ArrItem[0] = $k
;$ArrTree[0] = $k1
EndIf
_GUICtrlTreeView_EndUpdate($handTree)
EndFunc
Func _CreateIniCfg($path,$main = 0,$user="",$pass="",$swadd="",$swname="",$swi="",$swmo="")
Local $file
Switch $main
Case 0
$file = FileOpen($path,2)
If $file = -1 Then
MsgBox(0,"Error","不能打开文件!") ; 不能打开文件
Exit
EndIf
FileWrite($file, "[中心大楼]" & @CRLF)
FileWrite($file, "Switch1=192.168.15.196|Cisco" & @CRLF)
FileWrite($file, "[五号大楼]" & @CRLF)
FileWrite($file, "Cisco=192.168.254.121|Cisco" & @CRLF)
FileClose($file)
Case 2
IniWrite($path,$swadd,$swname,$swi & "|" & $swmo)
Case 11
$file = FileOpen($path,2+8) ;cisco
If $file = -1 Then
;MsgBox(0,"Error","不能打开文件!") ; 不能打开文件
Return
EndIf
FileWrite($file, "[main]" & @CRLF)
FileWrite($file, "user=" & _MySimpleEncry( _Base64Encode($user)) & @CRLF)
FileWrite($file, "pass="& _MySimpleEncry( _Base64Encode($pass)) & @CRLF)
FileWrite($file, "[Cisco]" & @CRLF)
FileWrite($file, ";右边表示路由提示的文字(支持正则表示),左边表示当右边出现了什么那么就是执行的命令" & @CRLF)
FileWrite($file, ";user pass tftpip backname是固定的,若是左边是user那么程序里会输入用户名" & @CRLF)
FileWrite($file, "user=Username:" & @CRLF)
FileWrite($file, "pass=Password:" & @CRLF)
FileWrite($file, "enable=[-.\w]*>" & @CRLF)
If GUICtrlRead($Checkbox1) = $GUI_CHECKED Then
FileWrite($file, "pass=Password:" & @CRLF)
EndIf
FileWrite($file, "copy startup-config tftp:=[-.\w]*#" & @CRLF)
FileWrite($file, "tftpip=address" & @CRLF)
FileWrite($file, "backname=file" & @CRLF)
FileClose($file)
Case 12 ;Huawei
$file = FileOpen($path,2+8)
If $file = -1 Then
Return
EndIf
FileWrite($file, "[main]" & @CRLF)
FileWrite($file, "user=" & _MySimpleEncry( _Base64Encode($user)) & @CRLF)
FileWrite($file, "pass="& _MySimpleEncry( _Base64Encode($pass)) & @CRLF)
FileWrite($file, "[Huawei]" & @CRLF)
FileWrite($file, ";vrpcfg.txt是交换机上的配置文件。user,pass,serviceip,desfile是固定的,在程序里会自动替换为服务器地址,与保存的名称" & @CRLF)
FileWrite($file, ";在程序里会自动替换为服务器地址,与保存的名称" & @CRLF)
FileWrite($file, "pass=Password:" & @CRLF)
FileWrite($file, "system-view=<[-.\w]*>" & @CRLF)
FileWrite($file, "tftp put vrpcfg.txt //serviceip/desfile=\[[-.\w]*\]" & @CRLF)
FileClose($file)
Case 13 ;H3C
$file = FileOpen($path,2+8)
If $file = -1 Then
Return
EndIf
FileWrite($file, "[main]" & @CRLF)
FileWrite($file, "user=" & _MySimpleEncry( _Base64Encode($user)) & @CRLF)
FileWrite($file, "pass="& _MySimpleEncry( _Base64Encode($pass)) & @CRLF)
FileWrite($file, "[H3C]" & @CRLF)
FileWrite($file, ";pass,crlf(表示按回车),serviceip,desfile 是固定的(config.cfg表示交换机配置文件需要根据不同填写)" & @CRLF)
FileWrite($file, "pass=Password:" & @CRLF)
FileWrite($file, "crlf=login" & @CRLF)
FileWrite($file, "tftp serviceip put config.cfg desfile=<[-.\w]*>" & @CRLF)
FileClose($file)
EndSwitch
EndFunc
Func _GetINIinfo($path,$sec,$secname)
Local $rvar = IniRead($path, $sec, $secname, "")
Local $arr = StringSplit($rvar,"|") ;分割
If $arr[0] = 2 Then
GUICtrlSetData ($Input1 , $arr[1] )
;GUICtrlSetData($Input, @ScriptDir & "\backup\" & $sec & "\" & $secname)
GUICtrlSetData($Input6,$arr[2])
EndIf
EndFunc
Func _BackupSwitch($swip,$swmode,$path) ;交换机ip 交换机型号 ini文件路径
Local $socket,$recvstr,$swuser,$swpass,$tftp,$iniresult,$i,$check
Local $sleep = 300
GUICtrlSetState($Button1,$GUI_DISABLE)
;从ini文件读取一些初始化信息
;$tftp = IniRead($path,"main","tftp","") ;tftp服务器ip地址
$tftp = GUICtrlRead($Input8)
$swuser = IniRead($path,"main","user","") ;交换机的用户名
$swpass = IniRead($path,"main","pass","") ;交换机的密码
If $tftp ="" Or $swuser="" Or $swpass="" Then
MsgBox(0,"Error","请配置tftp,user,pass")
Return
EndIf
$swuser = BinaryToString(_Base64Decode(_MySimpleDeEncry($swuser)))
$swpass = BinaryToString(_Base64Decode(_MySimpleDeEncry($swpass)))
;MsgBox(0,$swuser,$swpass)
;Exit
;从ini文件读取一些初始化信息
;=======================>telnet开始
TCPStartup()
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
$socket = TCPConnect($swip, 23) ;固定23,因为用的是telnet
If $socket = -1 Then
MsgBox(0,"Connect Error","连接交换机ip地址出错")
Return
EndIf
Sleep($sleep)
;$recvstr = TCPRecv($socket,4096) ;返回telnet接受的数据
;;;;================================================
Switch $swmode
Case "Cisco"
$iniresult=IniReadSection($path,$swmode) ;从ini读取交换机型号的模板
For $i=1 To $iniresult[0][0] ;[0][0]存放的是个数 关键字=$var[$i][0] 值=$var[$i][1]
Sleep($sleep)
$recvstr = _ReadEndLine(TCPRecv($socket,4096))
;MsgBox(0,"",$recvstr)
;MsgBox(0,$iniresult[$i][0],$iniresult[$i][1])
Sleep($sleep)
If StringRegExp($recvstr,"(?i)" & $iniresult[$i][1],0) Then
Switch $iniresult[$i][0] ;左边的命令,当user pass 等固定的字符串时会执行别的命令 user pass tftpip backname
Case "user"
TCPSend($socket, $swuser & @CRLF) ;发送用户名
Sleep($sleep)
Case "pass"
TCPSend($socket, $swpass & @CRLF) ;发送密码
Sleep($sleep)
Case "tftpip"
TCPSend($socket, $tftp & @CRLF) ;发送tftp ip address
Sleep($sleep)
Case "backname"
TCPSend($socket, $swip & @HOUR & @MIN & @SEC & ".txt" & @CRLF) ;发送 文件名 @YEAR & @MON & @MDAY
Sleep($sleep)
Case Else ;其它
TCPSend($socket, $iniresult[$i][0] & @CRLF)
Sleep($sleep)
EndSwitch
EndIf
Next
Case "Huawei"
$iniresult=IniReadSection($path,$swmode) ;从ini读取交换机型号的模板
For $i=1 To $iniresult[0][0]
Sleep($sleep)
$recvstr = _ReadEndLine(TCPRecv($socket,4096))
;MsgBox(0,"",$recvstr)
;MsgBox(0,$iniresult[$i][0],$iniresult[$i][1])
Sleep($sleep)
If StringRegExp($recvstr,"(?i)" & $iniresult[$i][1],0) Then ;右边可以正则表达式
Switch $iniresult[$i][0] ;左边的关键值
Case "user"
TCPSend($socket, $swuser & @CRLF) ;发送用户名
Sleep($sleep)
Case "pass"
TCPSend($socket, $swpass & @CRLF) ;发送密码
Sleep($sleep)
Case Else ;其它
If StringRegExp($iniresult[$i][0],"(?i)tftp",0) Then ;即是最后一条 tftp上传命令
TCPSend($socket,StringRegExpReplace(StringRegExpReplace($iniresult[$i][0],"serviceip",$tftp),"desfile",$swip & @HOUR & @MIN & @SEC & ".txt") & @CRLF )
Else
TCPSend($socket, $iniresult[$i][0] & @CRLF)
Sleep($sleep)
EndIf
EndSwitch
EndIf
Next
Case "H3C"
$iniresult=IniReadSection($path,$swmode) ;从ini读取交换机型号的模板
For $i=1 To $iniresult[0][0]
Sleep($sleep)
$recvstr = _ReadEndLine(TCPRecv($socket,4096))
Sleep($sleep)
If StringRegExp($recvstr,"(?i)" & $iniresult[$i][1],0) Then
Switch $iniresult[$i][0] ;左边的关键值
Case "user"
TCPSend($socket, $swuser & @CRLF) ;发送用户名
Sleep($sleep)
Case "pass"
TCPSend($socket, $swpass & @CRLF) ;发送密码
Sleep($sleep)
Case "crlf"
TCPSend($socket, @CRLF) ;发送回车
Sleep($sleep)
Case Else ;其它
If StringRegExp($iniresult[$i][0],"(?i)tftp",0) Then ;即是最后一条 tftp上传命令
TCPSend($socket,StringRegExpReplace(StringRegExpReplace($iniresult[$i][0],"serviceip",$tftp),"desfile",$swip & @HOUR & @MIN & @SEC & ".txt") & @CRLF )
Else
TCPSend($socket, $iniresult[$i][0] & @CRLF)
Sleep($sleep)
EndIf
EndSwitch
EndIf
Next
EndSwitch
;检查是否完成 开始只备份思科的,后来加入华为,所以这里需要改。比如华为交换机那里这里完成的标志是[\w]这种格式。
$check = 50
While $check
$recvstr = _ReadEndLine(TCPRecv($socket,4096))
If StringRegExp($recvstr,"(?i)\w#",0) Then
ExitLoop
EndIf
Sleep($sleep)
$check = $check -1
WEnd
;MsgBox(0,"",$check)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;关闭连接
TCPCloseSocket($Socket)
TCPShutdown()
GUICtrlSetState($Button1,$GUI_ENABLE)
EndFunc
Func _ReadEndLine($str) ;返回从tcprecv接收到的数据最后一行字符串
Local $resarr
$resarr = StringSplit($str,@CRLF)
Return $resarr[$resarr[0]]
EndFunc
;Func _LoadINI($path) ;读取一些tftp地址 用户与密码
; $tftp = IniRead($path,"main","tftp","")
; $user = IniRead($path,"main","user","")
; $pass = IniRead($path,"main","pass","")
; If $tftp ="" Or $user="" Or $pass="" Then
; MsgBox(0,"Error","请配置tftp,user,pass")
; Exit
; EndIf
;EndFunc
Func _ExistsTFTP()
Local $process = "TFTPServer.exe"
Local $PID = ProcessExists($process)
If Not $PID Then
_StartTFTP()
EndIf
EndFunc
Func _StartTFTP()
Local $path = @ScriptDir & "\TFTPServer\TFTPServer.exe"
;Local $check = 10
Local $process = "TFTPServer.exe"
Local $PID; = ProcessExists($process)
;Local $winname
;GUICtrlSetState($Button4,$GUI_DISABLE)
If Not FileExists($path) Then
MsgBox(0,"Error","请检查TFTPServer文件夹下是否有TFTPServer.exe文件")
Return
EndIf
Run($path)
Sleep(500)
;While $check
; $PID = ProcessExists($process)
; Sleep(200)
; If $PID Then
; $winname=_WinGetByPID($PID)
; Sleep(200)
; WinSetState($winname, "", @SW_HIDE)
; ExitLoop
; EndIf
; $check = $check -1
;WEnd
;MsgBox(0,"","dd")
;GUICtrlSetState($Button4,$GUI_ENABLE)
EndFunc
Func _StopTFTP()
Local $process = "TFTPServer.exe"
Local $PID = ProcessExists($process)
If $PID Then
ProcessClose($PID)
EndIf
EndFunc
Func _SetBackupPath() ;备份路径
Local $regpath = "HKEY_CURRENT_USER\Software\Cisco Systems Inc.\Cisco TFTP Server\1.1\Options"
;Local $process = "TFTPServer.exe"
;Local $PID = ProcessExists($process)
;If $PID Then
; ProcessClose($PID)
;EndIf
Local $path = FileSelectFolder("选择交换机配置保存文件夹.", "", 1)
If $path <> "" Then
_StopTFTP()
RegWrite($regpath,"TFTPRootDirectory","REG_SZ",$path) ;TFTPRootDirectory
_StartTFTP()
EndIf
EndFunc
Func _WinGetByPID($iPID, $nArray = 1);0 will return 1 base array; leaving it 1 will return the first visible window it finds
If IsString($iPID) Then $iPID = ProcessExists($iPID)
Local $aWList = WinList(), $sHold
For $iCC = 1 To $aWList[0][0]
If WinGetProcess($aWList[$iCC][1]) = $iPID And _
BitAND(WinGetState($aWList[$iCC][1]), 2) Then
If $nArray Then Return $aWList[$iCC][0]
$sHold &= $aWList[$iCC][0] & Chr(1)
EndIf
Next
If $sHold Then Return StringSplit(StringTrimRight($sHold, 1), Chr(1))
Return SetError(1, 0, 0)
EndFunc
Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
#forceref $hWnd, $iMsg, $iwParam
Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndTreeview,$h,$sname,$saddr ,$mche
$hWndTreeview = $hTreeView
If Not IsHWnd($hTreeView) Then $hWndTreeview = GUICtrlGetHandle($hTreeView)
$tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
$hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
$iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
$iCode = DllStructGetData($tNMHDR, "Code")
Switch $hWndFrom
Case $hWndTreeview
Switch $iCode
Case $NM_CLICK ; The user has clicked the left mouse button within the control
Return 0 ; zero to allow the default processing
Case $NM_DBLCLK ; The user has double-clicked the left mouse button within the control
For $h =1 To $ArrItem[0]
If _GUICtrlTreeView_GetSelected($hTreeView, $ArrItem[$h]) Then
$saddr = _GUICtrlTreeView_GetText($hTreeView, _GUICtrlTreeView_GetParentHandle($hTreeView, $ArrItem[$h]));从子节点读取到根节点
$sname = _GUICtrlTreeView_GetText($hTreeView, $ArrItem[$h])
;$switchname = $sname
_GetINIinfo($cfg,$saddr,$sname)
EndIf
Next
Return 0 ; zero to allow the default processing
Case $NM_RCLICK ; The user has clicked the right mouse button within the control
;MsgBox(0,"","Rigth")
;$mche = _GUICtrlMenu_TrackPopupMenu($Menu, $hWndTreeview, -1, -1, 1, 1, 2)
;If $mche <> 0 Then
; If $mche = $menudel Then
; MsgBox(0,"","")
; EndIf
;EndIf
$mche = _GUICtrlMenu_TrackPopupMenu($hContext, $hWndTreeview, -1, -1, 1, 1, 2)
If ($mche <> 0) Then
Switch $mche
Case $menudel
;
Case $menuexit
Exit
EndSwitch
EndIf
Return 0 ; zero to allow the default processing
Case $NM_RDBLCLK ; The user has clicked the right mouse button within the control
Return 0 ; zero to allow the default processing
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_NOTIFY
Func _MySimpleEncry($string)
Local $i,$rstr = ""
Local $arraytemp = _StringToArray($string)
;_ArrayDisplay($a)
For $i=0 To UBound($arraytemp)-1
;MsgBox(0,"",$arraytemp[$i])
;MsgBox(0,"",chr(Asc($arraytemp[$i])+10) ) ;转换成assci码的值加上10,再转成字符
$rstr = $rstr & ChrW(Asc($arraytemp[$i])+2)
Next
Return $rstr
EndFunc
Func _MySimpleDeEncry($string)
Local $i,$rstr = ""
Local $arraytemp = _StringToArray($string)
For $i=0 To UBound($arraytemp)-1
$rstr = $rstr & ChrW(Asc($arraytemp[$i])-2)
Next
;MsgBox(0,"",$rstr)
Return $rstr
EndFunc
Func _StringToArray($str)
Local $array[1],$c ;$c为转换的中间字符
$length=StringLen($str)
$c=StringMid($str,1,1)
$array[0]=$c
If $length>1 Then
For $i=2 To $length
$c=StringMid($str,$i,1)
_ArrayAdd($array,$c)
Next
EndIf
Return $array
EndFunc
Func _Base64Decode($Data)
Local $Opcode = "0xC81000005356578365F800E8500000003EFFFFFF3F3435363738393A3B3C3DFFFFFF00FFFFFF000102030405060708090A0B0C0D0E0F10111213141516171819FFFFFFFFFFFF1A1B1C1D1E1F202122232425262728292A2B2C2D2E2F303132338F45F08B7D0C8B5D0831D2E9910000008365FC00837DFC047D548A034384C0750383EA033C3D75094A803B3D75014AB00084C0751A837DFC047D0D8B75FCC64435F400FF45FCEBED6A018F45F8EB1F3C2B72193C7A77150FB6F083EE2B0375F08A068B75FC884435F4FF45FCEBA68D75F4668B06C0E002C0EC0408E08807668B4601C0E004C0EC0208E08847018A4602C0E00624C00A46038847028D7F038D5203837DF8000F8465FFFFFF89D05F5E5BC9C21000"
Local $CodeBuffer = DllStructCreate("byte[" & BinaryLen($Opcode) & "]")
DllStructSetData($CodeBuffer, 1, $Opcode)
Local $Ouput = DllStructCreate("byte[" & BinaryLen($Data) & "]")
Local $Ret = DllCall("user32.dll", "int", "CallWindowProc", "ptr", DllStructGetPtr($CodeBuffer), _
"str", $Data, _
"ptr", DllStructGetPtr($Ouput), _
"int", 0, _
"int", 0)
Return BinaryMid(DllStructGetData($Ouput, 1), 1, $Ret[0])
EndFunc
Func _Base64Encode($Data, $LineBreak = 76)
Local $Opcode = "0x5589E5FF7514535657E8410000004142434445464748494A4B4C4D4E4F505152535455565758595A6162636465666768696A6B6C6D6E6F707172737475767778797A303132333435363738392B2F005A8B5D088B7D108B4D0CE98F0000000FB633C1EE0201D68A06880731C083F901760C0FB6430125F0000000C1E8040FB63383E603C1E60409C601D68A0688470183F90176210FB6430225C0000000C1E8060FB6730183E60FC1E60209C601D68A06884702EB04C647023D83F90276100FB6730283E63F01D68A06884703EB04C647033D8D5B038D7F0483E903836DFC04750C8B45148945FC66B80D0A66AB85C90F8F69FFFFFFC607005F5E5BC9C21000"
Local $CodeBuffer = DllStructCreate("byte[" & BinaryLen($Opcode) & "]")
DllStructSetData($CodeBuffer, 1, $Opcode)
$Data = Binary($Data)
Local $Input = DllStructCreate("byte[" & BinaryLen($Data) & "]")
DllStructSetData($Input, 1, $Data)
$LineBreak = Floor($LineBreak / 4) * 4
Local $OputputSize = Ceiling(BinaryLen($Data) * 4 / 3)
$OputputSize = $OputputSize + Ceiling($OputputSize / $LineBreak) * 2 + 4
Local $Ouput = DllStructCreate("char[" & $OputputSize & "]")
DllCall("user32.dll", "none", "CallWindowProc", "ptr", DllStructGetPtr($CodeBuffer), _
"ptr", DllStructGetPtr($Input), _
"int", BinaryLen($Data), _
"ptr", DllStructGetPtr($Ouput), _
"uint", $LineBreak)
Return DllStructGetData($Ouput, 1)
EndFunc