本帖最后由 haodd 于 2011-4-21 17:45 编辑
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>
#NoTrayIcon
Global $item[1],$item2[1]
#Region ### START Koda GUI section ### Form=d:\#__共享读写\regwr\form1.kxf
$Form1 = GUICreate("注册表启动项", 420, 281, 192, 114)
$Group1 = GUICtrlCreateGroup("MACHINE组",336, 181, 73, 89)
$Radio1 = GUICtrlCreateRadio("添加", 347, 200, 57, 17)
$Radio2 = GUICtrlCreateRadio("删除", 347, 224, 57, 17)
$Radio3 = GUICtrlCreateRadio("读取", 347, 248, 57, 17)
$ListView1 = GUICtrlCreateListView("名称 | 键值",8, 152, 314, 126)
_regMACHINE()
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group2 = GUICtrlCreateGroup("USER组", 336, 45, 73, 89)
$Radio4 = GUICtrlCreateRadio("添加", 346, 63, 57, 17)
$Radio5 = GUICtrlCreateRadio("删除", 346, 87, 57, 17)
$Radio6 = GUICtrlCreateRadio("读取", 346, 111, 57, 17)
$ListView2 = GUICtrlCreateListView("名称 | 键值", 8, 8, 314, 126)
_regUSER()
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Select
Case $nMsg = $GUI_EVENT_CLOSE
ExitLoop
Case $nMsg = $radio1 And BitAND(GUICtrlRead($radio1), $GUI_CHECKED) = $GUI_CHECKED
MsgBox(4128, "你确定添加启动项吗 MACHINE","你确定添加启动项吗 MACHINE")
_addreg(0)
_GUICtrlListView_DeleteAllItems(GUICtrlGetHandle($ListView1))
_regMACHINE()
Case $nMsg = $radio2 And BitAND(GUICtrlRead($radio2), $GUI_CHECKED) = $GUI_CHECKED
If GUICtrlRead(GUICtrlRead($listview1)) <> "0" Then
$strsp = StringSplit(GUICtrlRead(GUICtrlRead($listview1)),"|")
MsgBox(4128, "你确定删除该项吗 MACHINE", "你确定删除该项吗 MACHINE"&@CRLF&"项名:"&$strsp[1]&@CRLF&"项值:"&$strsp[2])
_delreg(0,$strsp[1])
_GUICtrlListView_DeleteAllItems(GUICtrlGetHandle($ListView1))
_regMACHINE()
Else
MsgBox(4160,"请先选择你要删除的项 MACHINE","请先选择你要删除的项 MACHINE")
EndIf
Case $nMsg = $radio3 And BitAND(GUICtrlRead($radio3), $GUI_CHECKED) = $GUI_CHECKED
If GUICtrlRead(GUICtrlRead($listview1)) <> "0" Then
$strsp = StringSplit(GUICtrlRead(GUICtrlRead($listview1)),"|")
MsgBox(4160, "MACHINE","项名:"&$strsp[1]&@CRLF&"项值:"&$strsp[2])
Else
MsgBox(4160,"请先选择你要读取的内容 MACHINE","请先选择你要读取的内容 MACHINE")
EndIf
Case $nMsg = $radio4 And BitAND(GUICtrlRead($radio4), $GUI_CHECKED) = $GUI_CHECKED
MsgBox(4128, "你确定添加启动项吗 USER","你确定添加启动项吗 USER")
_addreg(1)
_GUICtrlListView_DeleteAllItems(GUICtrlGetHandle($ListView2))
_regUSER()
Case $nMsg = $radio5 And BitAND(GUICtrlRead($radio5), $GUI_CHECKED) = $GUI_CHECKED
If GUICtrlRead(GUICtrlRead($listview2)) <> "0" Then
$strsp = StringSplit(GUICtrlRead(GUICtrlRead($listview2)),"|")
MsgBox(4128, "你确定删除该项吗 USER", "你确定删除该项吗 USER"&@CRLF&"项名:"&$strsp[1]&@CRLF&"项值:"&$strsp[2])
_delreg(1,$strsp[1])
_GUICtrlListView_DeleteAllItems(GUICtrlGetHandle($ListView2))
_regUSER()
Else
MsgBox(4160,"请先选择你要删除的项 USER","请先选择你要删除的项 USER")
EndIf
Case $nMsg = $radio6 And BitAND(GUICtrlRead($radio6), $GUI_CHECKED) = $GUI_CHECKED
If GUICtrlRead(GUICtrlRead($listview2)) <> "0" Then
$strsp = StringSplit(GUICtrlRead(GUICtrlRead($listview2)),"|")
MsgBox(4160, "USER","项名:"&$strsp[1]&@CRLF&"项值:"&$strsp[2])
Else
MsgBox(4160,"请先选择你要读取的内容 USER","请先选择你要读取的内容 USER")
EndIf
EndSelect
WEnd
Func _regMACHINE()
For $ii = 1 to 100
$var = RegEnumVal("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run",$ii)
if @error <> 0 Then ExitLoop
$keyval = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run",$var)
_ArrayAdd($item,GUICtrlCreateListViewItem($var&"|"&$keyval, $listview1))
next
EndFunc
Func _regUSER()
For $i = 1 to 100
$var = RegEnumVal("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run", $i)
if @error <> 0 Then ExitLoop
$keyval = RegRead("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run",$var)
_ArrayAdd($item2,GUICtrlCreateListViewItem($var&"|"&$keyval, $listview2))
next
EndFunc
Func _addreg($add)
$enum = InputBox("请输入你要新建的项名","请输入你要新建的项名")
If @error Then Return False
$enumval = InputBox("请输入"&$enum&"的值","请输入"&$enum&"的值")
If @error Then Return False
If $add = 0 Then
RegWrite ("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run",$enum,"REG_SZ",$enumval)
ElseIf $add = 1 Then
RegWrite ("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run",$enum,"REG_SZ",$enumval)
EndIf
EndFunc
Func _delreg($del,$numkey)
If $del = 0 Then
RegDelete ("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run", $numkey)
ElseIf $del = 1 Then
RegDelete ("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run", $numkey)
EndIf
EndFunc
|