Jump to content

Project Documentation - GUI Registry Editor


Worth the Effort?  

18 members have voted

  1. 1. Does a program from such a project interst you?



Recommended Posts

I am looking for Developers for an AutoIT3 project to create a Working, Light-weight registry editor using AutoIT3.

1. It will not require an install

2. It will take command line arguments for Computer Name and Registry Key to open initially (both optional, of course)

3. It will have a robust search feature - hopefully including "search and delete" and "search and replace" though those may be on down the line.

4. I would like an "Edit in place" display instead of the "Modify" popup thing from Regedit. You are looking at the key and values, click edit and the values become editable.

5. "Favorites" are a must! Shortcuts to "HKLM\Software\Microsoft\Windows\Current Version\Uninstall" and other 'frequently used' locations that are not computer specific.

6. Search will be able to search entire registry or selected key.

7. It will NOT have to open the local registry and keep it open all the time.

It is going to target Computer and Network Administrators who know what they are doing.

I'm posting this to start the topic for work on this and to say :

If anyone knows of such a registry editor - save me some work and tell me about it!! ( O&O Registry Editor comes close, but no cookie. I've sent their developers some requests )

Edited by Graywalker
Link to comment
Share on other sites

  • 2 weeks later...

I've gotten some great help from the following posts :

Easy Associative Arrays

Assign, Eval and Variables

What I have so far is just a nice Tree-View of a registry.

Up next to work on :

Displaying data of hilighted key on the Right side

Make the "Hotkeys" menu work properly (open registry key)

Connect to remote computer registry

; A Better Techie Registry GUI
; The goal is to make a portable Registry Viewer and Editor
; that will offer several features to techies
; Registry Search (Entire Registry and Selected Key)
; SAFE Search and Replace and Search and Delete
; It takes a computer name as a command line argument
; a second command line for the registry key to open to
; both are optional
#include <AssocArray.au3> ; What I saved OHB's x function as.

Opt("ExpandVarStrings", 1)

Global $ScriptName, $computername, $regkey
Global $HotKeys[21][21]
Global $HKM[21]
Global $RegTree[21][21]
Global $RTM[21]
Global $RTMsk[10000]

For $i = 1 To $CmdLine[0]
    Select
        Case $i = 1
            $ScriptName = $CmdLine[1]
        Case $i = 2
            $computername = $CmdLine[2]
        Case $i = 3
            $regkey = $CmdLine[3]
    EndSelect
Next

If $computername = "" Then $computername = @ComputerName
If $regkey = "" Then $regkey = "HKLM"

;MsgBox(0,"test",$ScriptName & @CRLF & $computername & @CRLF & $regkey)

; Build the GUI
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <TreeViewConstants.au3>
#include <GuiTreeView.au3>
#include <WindowsConstants.au3>
#include <ProgressConstants.au3>
#region ### START Koda GUI section ### Form=I:\Scripts\RegEditor\BKRE.kxf
Global $BKRE = GUICreate("BKRegEdit", 726, 682, 192, 124, BitOR($WS_MAXIMIZEBOX, $WS_MINIMIZEBOX, $WS_SIZEBOX, $WS_THICKFRAME, $WS_SYSMENU, $WS_CAPTION, $WS_OVERLAPPEDWINDOW, $WS_TILEDWINDOW, $WS_POPUP, $WS_POPUPWINDOW, $WS_GROUP, $WS_TABSTOP, $WS_BORDER, $WS_CLIPSIBLINGS))
Global $MenuFile = GUICtrlCreateMenu("File")
Global $MenuFC = GUICtrlCreateMenuItem("Connect to", $MenuFile)
Global $MenuEdit = GUICtrlCreateMenu("Edit")
Global $MenuEO = GUICtrlCreateMenuItem("Options", $MenuEdit)
Global $MenuHotKeys = GUICtrlCreateMenu("HotKeys")
Global $search1 = GUICtrlCreateInput("", 480, 16, 121, 21)
Global $Button1 = GUICtrlCreateButton("Search", 608, 16, 75, 25, $WS_GROUP)
Global $TreeView1 = GUICtrlCreateTreeView(32, 80, 209, 561)
Global $ListView1 = GUICtrlCreateListView("", 256, 80, 458, 566)
GetConfig()
GUISetState(@SW_SHOW)
#endregion ### END Koda GUI section ###
;x_display('reg.hotkey')

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case 0
            ; nothing is happening, so do nothing
        Case $nMsg < 1
            ; Don't want to do anything with System Messages.
        Case $nMsg > 10
            ; The registry keys and hotkeys start at 14 mostly, so...
            Treeview1($nMsg)
    EndSwitch
WEnd

; The Functions

Func GetConfig()
    ; Read in the Options and Settings ini File
    ; Using a config.ini file to store options and extra keys
    ; Makes for easier customization
    Dim $configfile, $line
    Dim $hkcount = 1, $tvcount = 1

    $configfile = FileOpen(@ScriptDir & "\bkconfig.ini", 0)
    ;MsgBox(0,"Fileopen",@error)

    While 1
        $line = FileReadLine($configfile)
        If @error = -1 Then ExitLoop

        Select
            Case StringInStr($line, "##")
                ; this is a comment - ignore
            Case StringInStr($line, "!")
                ; this is a HotKeys entry - process
                $hotkeyentry = StringTrimLeft($line, 2)
                $ahotkeyentry = StringSplit($hotkeyentry, '"')
                $keypath = StringTrimRight($ahotkeyentry[1], 1)
                $keytitle = $ahotkeyentry[2]
                ;MsgBox(0,"HotKey","Should have a hotkey labeled " & @CRLF & $HotKeys[$hkcount][1])
                Assign("hotkey" & $hkcount,GUICtrlCreateMenuItem($keytitle, $MenuHotKeys))
                x("reg." & Eval("hotkey" & $hkcount) & ".name", $keytitle)
                x("reg." & Eval("hotkey" & $hkcount) & ".path", $keypath)
                x("reg." & Eval("hotkey" & $hkcount) & ".variable","hotkey" & $hkcount)
                $hkcount = $hkcount + 1

            Case StringInStr($line, "~")
                ; this is a Treeview entry - process
                $treeviewentry = StringTrimLeft($line, 2)
                $atreeviewentry = StringSplit($treeviewentry, '"')
                $keypath = StringTrimRight($atreeviewentry[1], 1)
                $keytitle = $atreeviewentry[2]
                Assign("main" & $tvcount,GUICtrlCreateTreeViewItem($keytitle, $TreeView1))
                x("reg." & Eval("main" & $tvcount) & ".name", $keytitle)
                x("reg." & Eval("main" & $tvcount) & ".path", $keypath)
                x("reg." & Eval("main" & $tvcount) & ".variable","main" & $tvcount)
                $tvcount = $tvcount + 1
            Case $line = ""
                ; Blank line - ignore
        EndSelect
    WEnd
    GUISetState(@SW_SHOW)
    FileClose($configfile)
EndFunc   ;==>GetConfig

Func Treeview1($nMsg)
    Dim $tvcount = 0, $i, $c
    ;MsgBox(0,"Message",$nMsg)
    _GUICtrlTreeView_BeginUpdate($TreeView1)

    $regkey = x("reg." & $nMsg & ".path")
    $title = x("reg." & $nMsg & ".title")
    $variable = x("reg." & $nMsg & ".variable")

    ; messy delete old data :(
    ; works, but has screen flash without the _GUICtrlTreeView_BeginUpdate($TreeView1) line
    GUICtrlSetState($nMsg,$TVE_COLLAPSE)

    $c = 1
    While 1
        $subkey = Eval("$variable$" & "_" & "$c$")
        $isdeclared = IsDeclared("$variable$" & "_" & "$c$")
        ;MsgBox(0,"$variable$_$c$", $subkey & @CRLF & $variable & @CRLF & "Delcared? " & $isdeclared & @CRLF & "$variable$" & "_" & "$c$")
        If IsInt($subkey) Then
            GUICtrlDelete($subkey)
        Else
            ExitLoop
        EndIf
        $c = $c + 1
    WEnd

    $c = 1
    While 1
        $key = RegEnumKey($regkey,$c)
        If $key = "" Then ExitLoop
        $path = $regkey & "\" & $key
        $title = $key
        Assign("$variable$" & "_" & "$c$",GUICtrlCreateTreeViewItem($key,$nMsg),2)
        x("reg." & Eval("$variable$" & "_" & "$c$") & ".path", $path)
        x("reg." & Eval("$variable$" & "_" & "$c$") & ".title", $title)
        x("reg." & Eval("$variable$" & "_" & "$c$") & ".variable", $variable & "_" & $c)
        $c = $c+1
    WEnd

    _GUICtrlTreeView_EndUpdate($TreeView1)
    GUICtrlSetState($nMsg,$GUI_EXPAND)
    GUISetState(@SW_SHOW)
    ;x_display()
EndFunc
Edited by Graywalker
Link to comment
Share on other sites

Moving right along.

I've got the Hotkeys working like I want - maybe not like expected, but like I want...

Got the right-side display working.

Got connect to computer working.

Started to set up editing.... just not sure how I want to proceed. Edit section at the bottom or try for Right Click editing??

Search is probably a long way away... and have not done stress testing to discover bugs...

If anyone wants to take a look at the code and make suggestions, improvements, etc... Please do! :mellow:

; A Better Techie Registry GUI
; The goal is to make a portable Registry Viewer and Editor
; that will offer several features to techies
; Registry Search (Entire Registry and Selected Key)
; SAFE Search and Replace and Search and Delete
; It takes a computer name as a command line argument
; a second command line for the registry key to open to
; both are optional
#include <AssocArray.au3> ; What I saved OHB's x function as.
Opt("ExpandVarStrings", 1)

Global $ScriptName, $computername, $regkey


For $i = 1 To $CmdLine[0]
    Select
        Case $i = 1
            $ScriptName = $CmdLine[1]
        Case $i = 2
            $computername = $CmdLine[2]
        Case $i = 3
            $regkey = $CmdLine[3]
    EndSelect
Next

If $computername = "" Then $computername = @ComputerName
If $regkey = "" Then $regkey = "HKLM"

;MsgBox(0,"test",$ScriptName & @CRLF & $computername & @CRLF & $regkey)

; Build the GUI
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <TreeViewConstants.au3>
#include <GuiTreeView.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>

#region ### START Koda GUI section ### Form=I:\Scripts\RegEditor\BKRE.kxf
Global $BKRE = GUICreate("BKRegEdit", 726, 682, 192, 124, BitOR($WS_MAXIMIZEBOX, $WS_MINIMIZEBOX, $WS_SIZEBOX, $WS_THICKFRAME, $WS_SYSMENU, $WS_CAPTION, $WS_OVERLAPPEDWINDOW, $WS_TILEDWINDOW, $WS_POPUP, $WS_POPUPWINDOW, $WS_GROUP, $WS_TABSTOP, $WS_BORDER, $WS_CLIPSIBLINGS))
Global $MenuFile = GUICtrlCreateMenu("File")
Global $MenuFC = GUICtrlCreateMenuItem("Connect to", $MenuFile)
Global $MenuEdit = GUICtrlCreateMenu("Edit")
Global $MenuEO = GUICtrlCreateMenuItem("Options", $MenuEdit)
Global $MenuHotKeys = GUICtrlCreateMenu("HotKeys")
Global $pclabel = GUICtrlCreateLabel($computername, 20, 50, 150, 21)
Global $search1 = GUICtrlCreateInput("", 480, 16, 121, 21)
Global $Button1 = GUICtrlCreateButton("Search", 608, 16, 75, 25, $WS_GROUP)
Global $TreeView1 = GUICtrlCreateTreeView(20, 80, 209, 500)
Global $ListView1 = GUICtrlCreateListView("Value|Type|Data", 256, 80, 458, 500)
Global $Keylabel = GUICtrlCreateLabel("Key",20,600,50,21)
Global $Keyedit = GUICtrlCreateInput("",72,600,150,21)
Global $vallable = GUICtrlCreateLabel("Value",225,600,50,21)
Global $valedit = GUICtrlCreateInput("",276,600,150,21)
Global $datlable = GUICtrlCreateLabel("Data",428,600,50,21)
Global $datedit = GUICtrlCreateInput("",480,600,150,21)
GetConfig()
GUISetState(@SW_SHOW)
#endregion ### END Koda GUI section ###
;x_display('reg.hotkey')

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case 0
            ; nothing is happening, so do nothing
        Case $nMsg = $MenuFC
            Connectto()
        Case $nMsg < 1
            ; Don't want to do anything with System Messages.
        Case $nMsg > 10
            ; The registry keys and hotkeys start at 14 mostly, so...
            Treeview1($nMsg)
    EndSwitch
WEnd

; The Functions

Func GetConfig()
    ; Read in the Options and Settings ini File
    ; Using a config.ini file to store options and extra keys
    ; Makes for easier customization
    Dim $configfile, $line
    Dim $hkcount = 1, $tvcount = 1
    Global $hotkeyhandles = 0

    $configfile = FileOpen(@ScriptDir & "\bkconfig.ini", 0)
    ;MsgBox(0,"Fileopen",@error)

    While 1
        $line = FileReadLine($configfile)
        If @error = -1 Then ExitLoop

        Select
            Case StringInStr($line, "##")
                ; this is a comment - ignore
            Case StringInStr($line, "!")
                ; this is a HotKeys entry - process
                $hotkeyentry = StringTrimLeft($line, 2)
                $ahotkeyentry = StringSplit($hotkeyentry, '"')
                $keypath = StringTrimRight($ahotkeyentry[1], 1)
                If $computername <> @ComputerName Then
                    $keypath = "\\" & $computername & "\" & $keypath
                EndIf
                $keytitle = $ahotkeyentry[2]
                ;MsgBox(0,"HotKey","Should have a hotkey labeled " & @CRLF & $HotKeys[$hkcount][1])
                Assign("hotkey" & $hkcount, GUICtrlCreateMenuItem($keytitle, $MenuHotKeys))
                x("reg." & Eval("hotkey" & $hkcount) & ".title", $keytitle)
                x("reg." & Eval("hotkey" & $hkcount) & ".path", $keypath)
                x("reg." & Eval("hotkey" & $hkcount) & ".variable", "hotkey" & $hkcount)
                $hkcount = $hkcount + 1
                $hotkeyhandles = $hotkeyhandles & Eval("hotkey" & $hkcount) & ","

            Case StringInStr($line, "~")
                ; this is a Treeview entry - process
                $treeviewentry = StringTrimLeft($line, 2)
                $atreeviewentry = StringSplit($treeviewentry, '"')
                $keypath = StringTrimRight($atreeviewentry[1], 1)
                If $computername <> @ComputerName Then
                    $keypath = "\\" & $computername & "\" & $keypath
                EndIf
                $keytitle = $atreeviewentry[2]
                Assign("main" & $tvcount, GUICtrlCreateTreeViewItem($keytitle, $TreeView1))
                x("reg." & Eval("main" & $tvcount) & ".name", $keytitle)
                x("reg." & Eval("main" & $tvcount) & ".path", $keypath)
                x("reg." & Eval("main" & $tvcount) & ".variable", "main" & $tvcount)
                $tvcount = $tvcount + 1
            Case $line = ""
                ; Blank line - ignore
        EndSelect
    WEnd
    GUISetState(@SW_SHOW)
    FileClose($configfile)
EndFunc   ;==>GetConfig

Func Treeview1($nMsg)
    Dim $tvcount = 0, $i, $c
    $type = ""
    ;MsgBox(0,"Message",$nMsg)
    _GUICtrlTreeView_BeginUpdate($TreeView1)

    $regkey = x("reg." & $nMsg & ".path")
    $title = x("reg." & $nMsg & ".title")
    $variable = x("reg." & $nMsg & ".variable")
    $type = x("reg." & $nMsg & ".type")

    If StringInStr($variable, "_val") Then
        ; Variable contained _val, so a value was clicked - need to edit it!!
        _EditVal($nMsg, $regkey, $title, $variable, $type)
    Else
        If StringInStr($variable, "hotkey") Then
            $nMsg = InsertHotkey($nMsg, $regkey, $title, $variable, $type)
            $regkey = x("reg." & $nMsg & ".path")
            $title = x("reg." & $nMsg & ".title")
            $variable = x("reg." & $nMsg & ".variable")
            $type = x("reg." & $nMsg & ".type")
        EndIf
        ; messy delete old data :(
        ; works, but has screen flash without the _GUICtrlTreeView_BeginUpdate($TreeView1) line
        GUICtrlSetState($nMsg, $TVE_COLLAPSE)

        $c = 1
        While 1
            $subkey = Eval("$variable$" & "_" & "$c$")
            $isdeclared = IsDeclared("$variable$" & "_" & "$c$")
            ;MsgBox(0,"$variable$_$c$", $subkey & @CRLF & $variable & @CRLF & "Delcared? " & $isdeclared & @CRLF & "$variable$" & "_" & "$c$")
            If IsInt($subkey) Then
                GUICtrlDelete($subkey)
            Else
                ExitLoop
            EndIf
            $c = $c + 1
        WEnd

        ; Start creating the sub-keys of the Item clicked on.
        $c = 1
        While 1
            $key = RegEnumKey($regkey, $c)
            If $key = "" Then ExitLoop
            $path = $regkey & "\" & $key
            $title = $key
            Assign("$variable$" & "_" & "$c$", GUICtrlCreateTreeViewItem($key, $nMsg), 2)
            x("reg." & Eval("$variable$" & "_" & "$c$") & ".path", $path)
            x("reg." & Eval("$variable$" & "_" & "$c$") & ".title", $title)
            x("reg." & Eval("$variable$" & "_" & "$c$") & ".variable", $variable & "_" & $c)
            $c = $c + 1
        WEnd

        ; Display the Values and data of the hilighted key name

        _GUICtrlListView_DeleteAllItems($ListView1)
        $c = 1
        SetError(0)
        While 1
            $val = RegEnumVal($regkey, $c)
            If @error <> 0 Then ExitLoop
            $type = @extended
            If $val = "" Then
                $val = "(Default)"
            EndIf

            Switch $type
                Case 1
                    $typedisp = "REG_SZ"
                Case 2
                    $typedisp = "REG_EXPAND_SZ"
                Case 3
                    $typedisp = "REG_BINARY"
                Case 4
                    $typedisp = "REG_DWORD"
                Case 5
                    $typedisp = "REG_DWORD_BIG_ENDIAN"
                Case 6
                    $typedisp = "REG_LINK"
                Case 7
                    $typedisp = "REG_MULTI_SZ"
                Case 8
                    $typedisp = "REG_RESOURCE_LIST"
                Case 9
                    $typedisp = "REG_FULL_RESOURCE_DESCRIPTOR"
                Case 10
                    $typedisp = "REG_RESOURCE_REQUIREMENTS_LIST"
            EndSwitch

            $data = RegRead($regkey, $val)
            If $data = "" Then
                $data = "value not set"
            EndIf
            Assign("$variable$" & "_val" & "$c$", GUICtrlCreateListViewItem($val & "|" & $typedisp & "|" & $data, $ListView1))
            x("reg." & Eval("$variable$" & "_val" & "$c$") & ".path", $regkey)
            x("reg." & Eval("$variable$" & "_val" & "$c$") & ".title", $val)
            x("reg." & Eval("$variable$" & "_val" & "$c$") & ".type", $type)
            x("reg." & Eval("$variable$" & "_val" & "$c$") & ".typedisp", $typedisp)
            x("reg." & Eval("$variable$" & "_val" & "$c$") & ".variable", $variable & "_val" & $c)
            $c = $c + 1
            $type = ""
        WEnd

    EndIf

    ; Show the results

    _GUICtrlTreeView_EndUpdate($TreeView1)
    GUICtrlSetState($nMsg, $GUI_EXPAND)
    GUISetState(@SW_SHOW)
    ;x_display()
EndFunc   ;==>Treeview1

Func _EditVal($nMsg, $regkey, $title, $variable, $type)
        ; Testing msgbox for a 'holder' function
        MsgBox(0, "Editing", $title & @CRLF & $type & @CRLF & $regkey)

EndFunc

Func InsertHotkey($nMsg, $regkey, $title, $variable, $type)
    ;MsgBox(0,"Getting here","InsertHotkey function start")
    Assign("$variable$" & "_" & "HK", GUICtrlCreateTreeViewItem($title, $TreeView1), 2)
    ;If $computername <> @ComputerName Then
    ;   $regkey = "\\" & $computername & "\" & $regkey
    ;EndIf
    Dim $c = 1
    While 1
        $key = RegEnumKey($regkey, $c)
        If $key = "" Then ExitLoop
        $path = $regkey & "\" & $key
        $title = $key
        Assign("$title$" & "_" & "$c$", GUICtrlCreateTreeViewItem($key, Eval("$variable$" & "_" & "HK")), 2)
        x("reg." & Eval("$title$" & "_" & "$c$") & ".path", $path)
        x("reg." & Eval("$title$" & "_" & "$c$") & ".title", $title)
        x("reg." & Eval("$title$" & "_" & "$c$") & ".variable", $title & "_" & $c)
        $c = $c + 1
    WEnd
    Return (Eval("$variable$" & "_" & "$c$"))
EndFunc   ;==>InsertHotkey

Func Connectto()
    $computername = InputBox("Connect To :", "Computer Name : ")
    _GUICtrlTreeView_DeleteAll($TreeView1)
    GUICtrlSetData($pclabel, $computername)
    GetConfig()
EndFunc   ;==>Connectto
Edited by Graywalker
Link to comment
Share on other sites

_GUICtrlTreeView_DeleteAll is not working properly!

Almost nothing in the _GUICtrlTreeView (GuiTreeView.au3) is working as expected.

And I keep forgetting to use the ",2" with "Assign" to make it Global!! DOAH!!

Aaaarrrgghhh!!!

Edited by Graywalker
Link to comment
Share on other sites

  • 3 weeks later...

I am trying to implement the code into my script, and I almost finished. But there is still only one problem:

I have "Opt("GUIOnEventMode", 1)" set, so the GuiGetMsg() function won't work. I am trying to "convert" the whole While thing to GUIRegisterMsg(WM_COMMAND,... something, but I am only a newbie at AutoIt. Can please someone help?

BTW, I am working on the editing part of Graywalker's script, I hope I can produce something that you will like.:blink:

Link to comment
Share on other sites

Hi!

I am interested in this project, but I can't use the source code because the config file is missing. Can you post it? (But for me it would be better not to use a config file.)

Regards

Thomas

I use a config file to make it totally portable (no install) and highly customizable. Below is the contents of bkconfig.ini

## RegEditBK Configuration File
## Double hash = comments
## ! = HotKeys entry
## ~ = Registry Key for Left-side TreeView
## " = beginning of title or label text
## If you are using "Edit : Options" you must close this
## file before continuing. :D


## Hotkeys - current max entries = 20
! HKLM\SOFTWARE\MICROSOFT\WINDOWS\CURRENTVERSION\UNINSTALL " WIN UNINSTALL
! HKLM\SOFTWARE\MICROSOFT\WINDOWS\CURRENTVERSION\RUN "HKLM Run
! HKCU\SOFTWARE\MICROSOFT\WINDOWS\CURRENTVERSION\RUN "HKCU Run

## Registry Tree View - current max entries = 20
## This will allow you to control the order of keys displayed
~ HKEY_LOCAL_MACHINE "HKEY_LOCAL_MACHINE
~ HKEY_CURRENT_USER "HKEY_CURRENT_USER
~ HKEY_USERS "HKEY_USERS
~ HKEY_CLASSES_ROOT "HKEY_CLASSES_ROOT
~ HKEY_CURRENT_CONFIG "HKEY_CURRENT_CONFIG
## Example extra entry : 
## ~ HKLM\SOFTWARE\MICROSOFT\WINDOWS\CURRENTVERSION\RUN "HKLM Windows Run

Work has been hectic... patches! patches! patches!!

Edited by Graywalker
Link to comment
Share on other sites

Would it be possible to do some sort of "track changes" function? Like scan the registry once, user does something, scan a second time and display the keys that changed?

It would be possible - but not within the scope of the project. I want to keep it simple, small and quick.

Plus, I don't think you'd need to do that very often and tools already exist. For what you are asking, I would use windiff or winmerge. Remote to the registry, export it as a .reg file, let the user do their thing, refresh and export the registry again, then use Winxxx to compare the two files.

Link to comment
Share on other sites

Hi!

I would like to post my "version" of your code. I made "some" modifications to fit my needs, but it is still having issues - the treeview "hides" the subkeys if I click on their "parent" key or even I can make disappear the whole treeview by clicking on it in an appropiate way.

I added a registry searching function - I borrowed the code from here:

http://www.autoitscript.com/forum/index.php?showtopic=9588 - _RegSearch

Unfortunately it is VERY slow... Would be better to find a faster code.

So my modified code:

#NoTrayIcon
#requireadmin
#include <AssocArray.au3>
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GuiListBox.au3>
#include <GuiListView.au3>
#include <GuiTreeView.au3>
#include <WindowsConstants.au3>
$header = "AutoIT Registry Editor"
Global $treeview1, $sresult, $reg_new, $typedisp, $regkey, $regui, $regsearch, $reg_search, $chb_key, $chb_name, $chb_value, $reg_new_name, $reg_new_type, $reg_new_value, $btn_reg_search, $btn_reg_cancel, $reg_new_pre_name, $reg_new_pre_type, $reg_new_pre_value, $reg_new_pre_key, $regfresh, $Msg
Global $regstop = 0
Global $searchgui = 0
Global $onemsg = 0
Global $twomsg = 0
Global $which = 1

Opt("GUICoordMode", 1)
Opt("ExpandVarStrings", 1)

$guiwidth = 640
$guiheight = 480
$mygui = GUICreate($header,$guiwidth,$guiheight,-1,-1,$WS_CAPTION + $WS_SYSMENU)
GUISetOnEvent($GUI_EVENT_CLOSE, "quit", $mygui)
$btn_quit = GUICtrlCreateButton("Quit",$guiwidth-110,$guiheight-35,100,30)
GUICtrlSetOnEvent($btn_quit,"quit")

GuiCtrlCreateGroup("", 10, 10,$guiwidth/3,$guiheight-134)
GUICtrlCreateGroup ("",-99,-99,1,1)
Global $TreeView1 = GUICtrlCreateTreeView(11,18,$guiwidth/3-2,$guiheight-145)
$context_regtree = GUICtrlCreateContextMenu($TreeView1)
$regnewkey = GUICtrlCreateMenuItem("New key",$context_regtree)
$regnewvalue = GUICtrlCreateMenuItem("New name",$context_regtree)
$regdelete = GUICtrlCreateMenuItem("Delete",$context_regtree)
$regsearch = GUICtrlCreateMenuItem("Search...",$context_regtree)
Global $ListView1 = GUICtrlCreateListView("Name|Type|Value",$guiwidth/3+20,16,($guiwidth/3)*2-30,$guiheight-140,$LVS_NOSORTHEADER)
GUICtrlSendMsg($ListView1,$LVM_SETCOLUMNWIDTH,0,100)
GUICtrlSendMsg($ListView1,$LVM_SETCOLUMNWIDTH,1,100)
GUICtrlSendMsg($ListView1,$LVM_SETCOLUMNWIDTH,2,100)
Global $keypath[5]
$keypath[0] = "HKEY_CLASSES_ROOT"
$keypath[1] = "HKEY_CURRENT_USER"
$keypath[2] = "HKEY_LOCAL_MACHINE"
$keypath[3] = "HKEY_USERS"
$keypath[4] = "HKEY_CURRENT_CONFIG"

Dim $hkcount = 1, $tvcount = 1
For $i = 0 To 4
    Assign("main" & $tvcount, GUICtrlCreateTreeViewItem($keypath[$i], $TreeView1))
    x("reg." & Eval("main" & $tvcount) & ".name", $keypath[$i])
    x("reg." & Eval("main" & $tvcount) & ".path", $keypath[$i])
    x("reg." & Eval("main" & $tvcount) & ".variable", "main" & $tvcount)
    $tvcount = $tvcount + 1
Next

Global $Keylabel = GUICtrlCreateLabel("Key:",10,$guiheight-88)
Global $reg_new_key = GUICtrlCreateInput("",45,$guiheight-90,$guiwidth/3-35,17)
Global $vallabel = GUICtrlCreateLabel("Name:",10,$guiheight-56,50,17)
Global $reg_new_name = GUICtrlCreateInput("",65,$guiheight-58,$guiwidth/3-55,17)
Global $datlabel = GUICtrlCreateLabel("Value:",$guiwidth/3+20,$guiheight-88,50,17)
Global $reg_new_value = GUICtrlCreateInput("",($guiwidth/3)+54,$guiheight-90,235,17)
GUICtrlCreateLabel("Type:",$guiwidth/3+20,$guiheight-56,50,17)
$reg_new_type = GuiCtrlCreatecombo("REG_NONE",$guiwidth/3+55,$guiheight-62,235,17,$CBS_DROPDOWN + $CBS_AUTOHSCROLL + $WS_VSCROLL + $CBS_UPPERCASE + $CBS_SIMPLE)
GUICtrlSetData($reg_new_type,"REG_SZ|REG_EXPAND_SZ|REG_BINARY|REG_DWORD|REG_DWORD_BIG_ENDIAN|REG_LINK|REG_MULTI_SZ|REG_RESOURCE_LIST|REG_FULL_RESOURCE_DESCRIPTOR|REG_RESOURCE_REQUIREMENTS_LIST","REG_NONE")
$btn_reg_delete = GUICtrlCreateButton("Delete",$guiwidth-110,$guiheight-105,100,30)
$btn_reg_write = GUICtrlCreateButton("Modify/Create",$guiwidth-110,$guiheight-70,100,30)

GUISetState(@SW_SHOW)
$handle = WinGetHandle($header)

While 1 
    $Msg = GUIGetMsg()
    Select
        Case $Msg = $GUI_EVENT_CLOSE
            Exit
        Case 0
            ; nothing is happening, so do nothing
        ;Case $Msg < 1
            ; Don't want to do anything with System Messages.
        Case $Msg = $btn_quit
            quit()
        Case $Msg = $regnewkey
            reg_pre_newkey()
        Case $Msg = $regnewvalue
            reg_pre_newvalue()
        Case $Msg = $regsearch
            reg_pre_search()
        Case $Msg = $regdelete
            reg_delete()
        Case $Msg = $btn_reg_delete
            reg_name_delete()
        Case $Msg = $btn_reg_write
            reg_newvalue()
        Case $Msg > 12  ; this case must be the last in the select/switch structure! This number must be changed depending on how many controls did you create
            $regfresh = $Msg
            Treeview1($Msg)
            msgstore($Msg)
    EndSelect
WEnd

Func reg_pre_search()
    Opt("GUIOnEventMode", 1)
    $regui = GUICreate($header&" - Search",480,320,-1,-1,"","",$handle)
    GUICtrlCreateLabel("Search for:",10,12)
    $reg_search = GUICtrlCreateInput("",70,12,150,17)
    GUICtrlCreateGroup("Search type",10,40,170,90)
    $chb_key = GUICtrlCreateCheckbox("Key",20,60)
    GUICtrlSetState($chb_key,$GUI_CHECKED)
    $chb_name = GUICtrlCreateCheckbox("Name",20,80)
    GUICtrlSetState($chb_name,$GUI_CHECKED)
    $chb_value = GUICtrlCreateCheckbox("Value",20,100)
    GUICtrlSetState($chb_value,$GUI_CHECKED)
    GUICtrlCreateGroup("",-99,-99,1,1) 
    $btn_reg_search = GUICtrlCreateButton("Search",365,10,100,30,$BS_DEFPUSHBUTTON)
    $btn_reg_cancel = GUICtrlCreateButton("Cancel",365,45,100,30)
    GUICtrlSetOnEvent($btn_reg_search,"reg_search")
    GUICtrlSetOnEvent($btn_reg_cancel,"regcancel")
    GUICtrlCreateLabel("Searching under:",10,140,100,17)
    $reg_new_key = GUICtrlCreateEdit($regkey,10,160,455,20,$ES_READONLY + $ES_AUTOHSCROLL)
    $sresult = GUICtrlCreateEdit("",10,185,455,100,$WS_HSCROLL + $WS_VSCROLL)
    GUISetState(@SW_SHOW,$regui)
EndFunc

Func reg_search()
    HotKeySet("{ESC}","regstop")
    $regstop = 0
    GUICtrlSetState($btn_reg_search,$GUI_DISABLE)
    GUICtrlSetState($btn_reg_cancel,$GUI_DISABLE)
    GUICtrlSetState($reg_search,$GUI_DISABLE)
    GUICtrlSetState($chb_key,$GUI_DISABLE)
    GUICtrlSetState($chb_name,$GUI_DISABLE)
    GUICtrlSetState($chb_value,$GUI_DISABLE)
    GUICtrlSetData($btn_reg_search,"Stop: ESC")
    $regsearching = GUICtrlRead($reg_search)
    If $regsearching = "" Then
        GUISetCursor()
        MsgBox(16,$header,"ERROR - no data entered","",$handle)
    Else
        $result = ""
        GUISetCursor(1,1)
        $whattosearch = 0
        If BitAND(GUICtrlRead($chb_key), $GUI_CHECKED) = $GUI_CHECKED Then
            $whattosearch += 1
        Endif
        If BitAND(GUICtrlRead($chb_name), $GUI_CHECKED) = $GUI_CHECKED Then
            $whattosearch += 2
        Endif
        If BitAND(GUICtrlRead($chb_value), $GUI_CHECKED) = $GUI_CHECKED Then
            $whattosearch += 4
        Endif
        $result = _RegSearch($regkey,$regsearching,$whattosearch)
        If $result = "" Then
            GUICtrlSetData($sresult,"No match")
            GUISetCursor()
        Else
            GUICtrlSetData($sresult,"Searching finished, here are the results:"&@CRLF&@CRLF&$result)
            GUISetCursor()
        Endif
    EndIf
    HotKeySet("{ESC}")
    GUICtrlSetData($btn_reg_search,"Search")
    GUICtrlSetState($btn_reg_search,$GUI_ENABLE)
    GUICtrlSetState($btn_reg_cancel,$GUI_ENABLE)
    GUICtrlSetState($reg_search,$GUI_ENABLE)
    GUICtrlSetState($chb_key,$GUI_ENABLE)
    GUICtrlSetState($chb_name,$GUI_ENABLE)
    GUICtrlSetState($chb_value,$GUI_ENABLE)
EndFunc

Func reg_pre_newkey()
    Select
        Case $regkey = ""
            MsgBox(16,"ERROR","You cannot create a new rootkey!")
        Case $regkey = "HKEY_LOCAL_MACHINE" Or $regkey = "HKEY_USERS"
            MsgBox(16,"ERROR","You cannot create a new key directly under "&$regkey)
        Case Else
            Opt("GUIOnEventMode", 1)
            $regui = GUICreate("New key",360,160,-1,-1,"","",$handle)
            GUICtrlCreateLabel("Creating key under this key:",10,10,220,18)
            GUICtrlCreateEdit($regkey,10,30,335,20,$ES_READONLY + $ES_AUTOHSCROLL)
            $reg_new = GUICtrlCreateInput("",10,62,220,17)
            $btn_reg_new = GUICtrlCreateButton("OK",245,60,100,30,$BS_DEFPUSHBUTTON)
            GUICtrlSetOnEvent($btn_reg_new,"reg_newkey")
            $btn_reg_cancel = GUICtrlCreateButton("Cancel",245,95,100,30)
            GUICtrlSetOnEvent($btn_reg_cancel,"regcancel")
            GUISetState(@SW_SHOW,$regui)
    EndSelect
EndFunc

Func reg_newkey()
    $reguj = GUICtrlRead($reg_new)
    RegWrite($regkey&"\"&$reguj)
    GUIDelete($regui)
    Opt("GUIOnEventMode", 0)
    Treeview1($regfresh)
EndFunc

Func reg_pre_newvalue()
    Opt("GUIOnEventMode", 1)
    $regui = GUICreate("New name",370,230,-1,-1,"","",$handle)
    GUICtrlCreateLabel("Creating name under this key:",10,10,220,17)
    $reg_new_pre_key = GUICtrlCreateEdit($regkey,10,30,345,20,$ES_READONLY + $ES_AUTOHSCROLL)
    GUICtrlCreateLabel("Name:",10,60,50,18)
    $reg_new_pre_name = GUICtrlCreateInput("",10,80,235,17)
    GUICtrlCreateLabel("Type:",10,105,50,17)
    $reg_new_pre_type = GuiCtrlCreatecombo("REG_NONE",10,122,235,17,$CBS_DROPDOWN + $CBS_AUTOHSCROLL + $WS_VSCROLL + $CBS_UPPERCASE + $CBS_SIMPLE)
    GUICtrlSetData($reg_new_pre_type,"REG_SZ|REG_EXPAND_SZ|REG_BINARY|REG_DWORD|REG_DWORD_BIG_ENDIAN|REG_LINK|REG_MULTI_SZ|REG_RESOURCE_LIST|REG_FULL_RESOURCE_DESCRIPTOR|REG_RESOURCE_REQUIREMENTS_LIST","REG_NONE")
    GUICtrlCreateLabel("Value:",10,152,50,18)
    $reg_new_pre_value = GUICtrlCreateInput("",10,172,235,17)
    $btn_reg_new = GUICtrlCreateButton("OK",255,130,100,30,$BS_DEFPUSHBUTTON)
    GUICtrlSetOnEvent($btn_reg_new,"reg_new_prevalue")
    $btn_reg_cancel = GUICtrlCreateButton("Cancel",255,165,100,30)
    GUICtrlSetOnEvent($btn_reg_cancel,"regcancel")
    GUISetState(@SW_SHOW,$regui)
    $searchgui = 1
EndFunc

Func reg_new_prevalue()
    $regnewname = GUICtrlRead($reg_new_pre_name)
    $regnewtype = GUICtrlRead($reg_new_pre_type)
    $regnewvalue = GUICtrlRead($reg_new_pre_value)
    $regkey = GUICtrlRead($reg_new_pre_key)
    RegWrite($regkey,$regnewname,$regnewtype,$regnewvalue)
    If $searchgui = 1 Then
        GUIDelete($regui)
        WinActivate($mygui)
    EndIf
    Treeview1($regfresh)
    Opt("GUIOnEventMode", 0)
EndFunc

Func reg_newvalue()
    $regnewname = GUICtrlRead($reg_new_name)
    $regnewtype = GUICtrlRead($reg_new_type)
    $regnewvalue = GUICtrlRead($reg_new_value)
    $regkey = GUICtrlRead($reg_new_key)
    RegWrite($regkey,$regnewname,$regnewtype,$regnewvalue)
    If $searchgui = 1 Then
        GUIDelete($regui)
        WinActivate($mygui)
    EndIf
    Treeview1($regfresh)
    Opt("GUIOnEventMode", 0)
EndFunc

Func reg_delete()
    Select
        Case $regkey = "HKEY_CLASSES_ROOT"
            MsgBox(16,"Delete key","ERROR - The whole "&$regkey&" key cannot be deleted!")
        Case $regkey = "HKEY_CURRENT_USER"
            MsgBox(16,"Delete key","ERROR - The whole "&$regkey&" key cannot be deleted!")
        Case $regkey = "HKEY_LOCAL_MACHINE"
            MsgBox(16,"Delete key","ERROR - The whole "&$regkey&" key cannot be deleted!")
        Case $regkey = "HKEY_USERS"
            MsgBox(16,"Delete key","ERROR - The whole "&$regkey&" key cannot be deleted!")
        Case $regkey = "HKEY_CURRENT_CONFIG"
            MsgBox(16,"Delete key","ERROR - The whole "&$regkey&" key cannot be deleted!")
        Case Else
            $answer = MsgBox(52,"Delete key","Are you sure you want to delete this key?"&@CRLF&@CRLF&$regkey,"",$handle)
            Select
                Case $answer = 6
                    RegDelete($regkey)
                    Switch $which
                        Case 1
                            Treeview1($onemsg)
                        Case 2
                            Treeview1($twomsg)
                    EndSwitch
                Case $answer = 7
            EndSelect
    EndSelect
EndFunc

Func reg_name_delete()
    $regnewname = GUICtrlRead($reg_new_name)
    $regnewtype = GUICtrlRead($reg_new_type)
    $regnewvalue = GUICtrlRead($reg_new_value)
    RegDelete($regkey,$regnewname)
    $regkey = GUICtrlRead($reg_new_key)
    Switch $which
        Case 1
            Treeview1($onemsg)
        Case 2
            Treeview1($twomsg)
    EndSwitch
EndFunc

Func regcancel()
    GUIDelete($regui)
    Opt("GUIOnEventMode", 0)
    WinActivate($header)
EndFunc

Func Treeview1($Msg)
    GUISetCursor(15,1)
    Dim $tvcount = 0, $i, $c
    $type = ""
    
    _GUICtrlTreeView_BeginUpdate($TreeView1)

    $regkey = x("reg." & $Msg & ".path")
    $title = x("reg." & $Msg & ".title")
    $variable = x("reg." & $Msg & ".variable")
    $type = x("reg." & $Msg & ".type")

    ;MsgBox(0,"Message",$regkey)

    If StringInStr($variable, "_val") Then
        _EditVal($Msg, $regkey, $title, $variable, $type)
    Else
        ; messy delete old data :(
        ; works, but has screen flash without the _GUICtrlTreeView_BeginUpdate($TreeView1) line
        GUICtrlSetState($Msg, $TVE_COLLAPSE)

        $c = 1
        While 1
            $subkey = Eval("$variable$" & "_" & "$c$")
            $isdeclared = IsDeclared("$variable$" & "_" & "$c$")
            ;MsgBox(0,"$variable$_$c$", $subkey & @CRLF & $variable & @CRLF & "Declared? " & $isdeclared & @CRLF & "$variable$" & "_" & "$c$")
            If IsInt($subkey) Then
                GUICtrlDelete($subkey)
            Else
                ExitLoop
            EndIf
            $c = $c + 1
        WEnd

        ; Start creating the sub-keys of the Item clicked on.
_GUICtrlListView_DeleteAllItems($ListView1) ; this line seems to be good here too...
        $c = 1
        While 1
            $key = RegEnumKey($regkey, $c)
            If $key = "" Then ExitLoop
            $path = $regkey & "\" & $key
            $title = $key
            Assign("$variable$" & "_" & "$c$", GUICtrlCreateTreeViewItem($key, $Msg), 2)
            x("reg." & Eval("$variable$" & "_" & "$c$") & ".path", $path)
            x("reg." & Eval("$variable$" & "_" & "$c$") & ".title", $title)
            x("reg." & Eval("$variable$" & "_" & "$c$") & ".variable", $variable & "_" & $c)
            $c = $c + 1
        WEnd

        ; Display the Values and data of the hilighted key name
        $c = 1
;_GUICtrlListView_DeleteAllItems($ListView1)    ; seems to be good here too, but anywhere I put this line, I still have gui issues...
        SetError(0)
        While 1
            $val = RegEnumVal($regkey, $c)
            If @error <> 0 Then ExitLoop
            $type = @extended
            If $val = "" Then
                $val = "(Default)"
            EndIf

            Switch $type
                Case 1
                    $typedisp = "REG_SZ"
                Case 2
                    $typedisp = "REG_EXPAND_SZ"
                Case 3
                    $typedisp = "REG_BINARY"
                Case 4
                    $typedisp = "REG_DWORD"
                Case 5
                    $typedisp = "REG_DWORD_BIG_ENDIAN"
                Case 6
                    $typedisp = "REG_LINK"
                Case 7
                    $typedisp = "REG_MULTI_SZ"
                Case 8
                    $typedisp = "REG_RESOURCE_LIST"
                Case 9
                    $typedisp = "REG_FULL_RESOURCE_DESCRIPTOR"
                Case 10
                    $typedisp = "REG_RESOURCE_REQUIREMENTS_LIST"
                Case Else
                    $typedisp = "REG_NONE"
            EndSwitch

            $data = RegRead($regkey, $val)
            If $data = "" Then
                $data = "(nem beállított érték)"
            EndIf
            Assign("$variable$" & "_val" & "$c$", GUICtrlCreateListViewItem($val & "|" & $typedisp & "|" & $data, $ListView1))
            x("reg." & Eval("$variable$" & "_val" & "$c$") & ".path", $regkey)
            x("reg." & Eval("$variable$" & "_val" & "$c$") & ".title", $val)
            x("reg." & Eval("$variable$" & "_val" & "$c$") & ".type", $type)
            x("reg." & Eval("$variable$" & "_val" & "$c$") & ".typedisp", $typedisp)
            x("reg." & Eval("$variable$" & "_val" & "$c$") & ".variable", $variable & "_val" & $c)
            $c = $c + 1
            $type = ""
        WEnd

    EndIf

    ; Show the results
    _GUICtrlTreeView_EndUpdate($TreeView1)
    GUICtrlSetState($Msg, $GUI_EXPAND)
    GUISetState(@SW_SHOW)
    ;x_display()
    GUISetCursor()
EndFunc

Func _EditVal($Msg, $regkey, $title, $variable, $type)
    $howmuch = StringInStr($variable,"val") ; looking for where the "val" string begins in the $variable
    $whichone = StringTrimLeft($variable,$howmuch+2)    ; cutting the characters from $variable until the end of "val" to determine which line was clicked
    $regfresh = $regfresh - $whichone   ; substracting the line number from $regfresh (=$Msg) we get the control id number where we are and which we have to refresh
    GUICtrlSetData($reg_new_key,$regkey)
    GUICtrlSetData($reg_new_name,$title)
    GUICtrlSetData($reg_new_type,$typedisp)
    $value = RegRead($regkey,$title)
    GUICtrlSetData($reg_new_value,$value)
EndFunc

Func regstop()
    If WinActive($header&" - Search") Then  ; check to see if the ESC was pressed in this program
        $regstop = 1
        GUICtrlSetData($btn_reg_search,"Stopping...")
    Endif
EndFunc

Func _RegSearch($sStartKey, $sSearchVal, $iType = 0x07, $fArray = False)
Local $v, $sVal, $k, $sKey, $sFound = "", $sFoundSub = "", $avFound[1] = [0]

    ; Trim trailing backslash, if present
    If StringRight($sStartKey, 1) = "\" Then $sStartKey = StringTrimRight($sStartKey, 1)

    ; Generate type flags
    If Not BitAND($iType, 0x07) Then Return SetError(1, 0, 0); No returns selected
    Local $fKeys = BitAND($iType, 0x1), $fValue = BitAND($iType, 0x2), $fData = BitAND($iType, 0x4), $fRegExp = BitAND($iType, 0x8)

    ; Check for wildcard
    If (Not $fRegExp) And ($sSearchVal == "*") Then
        ; Use RegExp pattern "." to match anything
        $iType += 0x8
        $fRegExp = 0x8
        $sSearchVal = "."
    EndIf

    ; This checks values and data in the current key
    If ($fValue Or $fData) Then
        $v = 1
        While $regstop = 0
            $sVal = RegEnumVal($sStartKey, $v)
            If @error = 0 Then
                ; Valid value - test its name
                If $fValue Then
                    If $fRegExp Then
                        If StringRegExp($sVal, $sSearchVal, 0) Then $sFound &= $sStartKey & "\" & $sVal & @CRLF
                    Else
                        If StringInStr($sVal, $sSearchVal) Then $sFound &= $sStartKey & "\" & $sVal & @CRLF
                    EndIf
                EndIf

                ; test its data
                If $fData Then
                    $readval = RegRead($sStartKey, $sVal)
                    If $fRegExp Then
                        If StringRegExp($readval, $sSearchVal, 0) Then $sFound &= $sStartKey & "\" & $sVal & " = " & $readval & @CRLF
                    Else
                        If StringInStr($readval, $sSearchVal) Then $sFound &= $sStartKey & "\" & $sVal & " = " & $readval & @CRLF
                    EndIf
                EndIf
                $v += 1
            Else
                ; No more values here
                ExitLoop
            EndIf
        WEnd
    EndIf
    
    ; This loop checks subkeys
    $k = 1
    While $regstop = 0
        $sKey = RegEnumKey($sStartKey, $k)
        If @error = 0 Then
            ; Valid key - test it's name
            If $fKeys Then
                If $fRegExp Then
                    If StringRegExp($sKey, $sSearchVal, 0) Then $sFound &= $sStartKey & "\" & $sKey & "\" & @CRLF
                Else
                    If StringInStr($sKey, $sSearchVal) Then $sFound &= $sStartKey & "\" & $sKey & "\" & @CRLF
                EndIf
            EndIf
        GUICtrlSetData($sresult,$sstartkey & "\" & $skey)
            ; Now search it
            $sFoundSub = _RegSearch($sStartKey & "\" & $sKey, $sSearchVal, $iType, False) ; use string mode to test sub keys
            If $sFoundSub <> "" Then $sFound &= $sFoundSub & @CRLF
        Else
            ; No more keys here
            ExitLoop
        EndIf
        $k += 1
    WEnd

    ; Return results
    If StringRight($sFound, 1) = @LF Then $sFound = StringTrimRight($sFound, 1)
    If $fArray Then
        If StringStripWS($sFound, 8) <> "" Then $avFound = StringSplit($sFound, @LF)
        Return $avFound
    Else
        Return $sFound
    EndIf
EndFunc

Func msgstore($Msg) ; used by reg_delete() function to refresh the tree after deleting a key
    Switch $which
        Case 1
            If $twomsg <> $Msg Then
                $onemsg = $Msg
                $which = 2
            EndIf
        Case 2
            If $onemsg <> $Msg Then
                $twomsg = $Msg
                $which = 1
            EndIf
    EndSwitch
EndFunc

Func quit()
    Exit
EndFunc

I would like to ask any of you to help me (and Graywalker) to make better the code, especially fix the issues with the treeview... As you can see I am newbie at autoit. And sorry for my english if it's not the best (not just here but in the code too:) ).

Edited by tkocsir
Link to comment
Share on other sites

  • 2 weeks later...

Haven't really had a chance to work on this any more, but just wanted to express my frustration at how most registry editors make you search the WHOLE registry instead of just the one key you know the subkey or value should be in... grrr...

Re-inspiring me to start back to work on this.

Link to comment
Share on other sites

  • 5 weeks later...

Getting a Lot closer to working the way I want it to!

New layout.

Almost to the actual Editing and adding of values and the adding/deleting of keys.

Not yet active :

* Search (within selected)

* Find and Replace (within selected)

* Find and Delete (need to figure out safe way to do this)

Config file has not changed (see above posts)

Here is the Latest code :

; A Better Techie Registry GUI
; The goal is to make a portable Registry Viewer and Editor
; that will offer several features to techies
; Registry Search (Entire Registry and Selected Key)
; SAFE Search and Replace and Search and Delete
; It takes a computer name as a command line argument
; a second command line for the registry key to open to
; both are optional
#include <AssocArray.au3> ; What I saved OHB's x function as.
Opt("ExpandVarStrings", 1)

Global $ScriptName, $computername, $regkey
Global $valarray[7], $keyarray[4]


For $i = 1 To $CmdLine[0]
    Select
        Case $i = 1
            $computername = $CmdLine[1]
        Case $i = 2
            $regkey = $CmdLine[2]
    EndSelect
Next

If $computername = "" Then $computername = @ComputerName
If $regkey = "" Then $regkey = "HKLM"

;MsgBox(0,"test",$ScriptName & @CRLF & $computername & @CRLF & $regkey)

; Build the GUI
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <StaticConstants.au3>
#include <TreeViewConstants.au3>
#include <WindowsConstants.au3>
#include <GuiTreeView.au3>
#include <GuiListView.au3>

#Region ### START Koda GUI section ### Form=I:\Scripts\RegEditor\BKRE.kxf
$BKRE = GUICreate("BKRegEdit", 724, 679, 199, 123,BitOR($WS_SIZEBOX, $WS_OVERLAPPEDWINDOW))
$pclabel = GUICtrlCreateLabel($computername, 20, 50, 150, 21)
$search1 = GUICtrlCreateInput("", 480, 16, 121, 21)
$searchbtn = GUICtrlCreateButton("Search", 608, 16, 75, 25, $WS_GROUP)
$TreeView1 = GUICtrlCreateTreeView(20, 80, 209, 500)
$ListView1 = GUICtrlCreateListView("Value|Type|Data", 256, 80, 458, 500)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 50)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 50)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 2, 50)
$Keyedit = GUICtrlCreateInput("", 19, 592, 204, 21)
$valedit = GUICtrlCreateInput("", 259, 592, 114, 21)
$datedit = GUICtrlCreateInput("", 505, 592, 204, 21)
$savevalbtn = GUICtrlCreateButton("Save : Add", 647, 624, 66, 25, 0)
$TypeCombo = GUICtrlCreateCombo("REG_SZ", 376, 592, 121, 25)
GUICtrlSetData($TypeCombo,"REG_EXPAND_SZ|REG_BINARY|REG_DWORD|REG_DWORD_BIG_ENDIAN|REG_LINK|REG_MULTI_SZ|REG_RESOURCE_LIST|REG_FULL_RESOURCE_DESCRIPTOR|REG_RESOURCE_REQUIREMENTS_LIST")
$DelValbtn = GUICtrlCreateButton("Delete", 256, 624, 75, 25, 0)
$DelKeyBtn = GUICtrlCreateButton("Delete Key", 16, 624, 75, 25, 0)
$AddKeybtn = GUICtrlCreateButton("Add Key", 144, 624, 75, 25, 0)
$MenuFile = GUICtrlCreateMenu("File")
$MenuFC = GUICtrlCreateMenuItem("Connect to", $MenuFile)
$MenuEdit = GUICtrlCreateMenu("Edit")
$MenuEO = GUICtrlCreateMenuItem("Options", $MenuEdit)
$MenuHotKeys = GUICtrlCreateMenu("HotKeys")
#EndRegion ### END Koda GUI section ###

GetConfig()
GUISetState(@SW_SHOW)

;x_display('reg.hotkey')

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case 0
            ; nothing is happening, so do nothing
        Case $nMsg = $MenuFC
            Connectto()
        Case $nMsg = $MenuEO
            EditOptions()
        Case $nMsg = $savevalbtn
            $hItem = _GUICtrlTreeView_GetSelection($TreeView1)
            _readkeys($hItem)

        Case $nMsg < 1
            ; Don't want to do anything with System Messages.
        Case $nMsg > 10
            ; The registry keys and hotkeys start at 14 mostly, so...
            Treeview1($nMsg)
    EndSwitch
WEnd

; The Functions

Func GetConfig()
    ; Read in the Options and Settings ini File
    ; Using a config.ini file to store options and extra keys
    ; Makes for easier customization
    Dim $configfile, $line
    Dim $hkcount = 1, $tvcount = 1
    Global $hotkeyhandles = 0

    $configfile = FileOpen(@ScriptDir & "\bkconfig.ini", 0)
    ;MsgBox(0,"Fileopen",@error)

    While 1
        $line = FileReadLine($configfile)
        If @error = -1 Then ExitLoop

        Select
            Case StringInStr($line, "##")
                ; this is a comment - ignore
            Case StringInStr($line, "!")
                ; this is a HotKeys entry - process
                $hotkeyentry = StringTrimLeft($line, 2)
                $ahotkeyentry = StringSplit($hotkeyentry, '"')
                $keypath = StringTrimRight($ahotkeyentry[1], 1)
                If $computername <> @ComputerName Then
                    $keypath = "\\" & $computername & "\" & $keypath
                EndIf
                $keytitle = $ahotkeyentry[2]
                ;MsgBox(0,"HotKey","Should have a hotkey labeled " & @CRLF & $HotKeys[$hkcount][1])
                Assign("hotkey" & $hkcount, GUICtrlCreateMenuItem($keytitle, $MenuHotKeys), 2)
                x("reg." & Eval("hotkey" & $hkcount) & ".title", $keytitle)
                x("reg." & Eval("hotkey" & $hkcount) & ".path", $keypath)
                x("reg." & Eval("hotkey" & $hkcount) & ".variable", "hotkey" & $hkcount)
                $hkcount = $hkcount + 1
                $hotkeyhandles = $hotkeyhandles & Eval("hotkey" & $hkcount) & ","

            Case StringInStr($line, "~")
                ; this is a Treeview entry - process
                $treeviewentry = StringTrimLeft($line, 2)
                $atreeviewentry = StringSplit($treeviewentry, '"')
                $keypath = StringTrimRight($atreeviewentry[1], 1)
                If $computername <> @ComputerName Then
                    $keypath = "\\" & $computername & "\" & $keypath
                EndIf
                $keytitle = $atreeviewentry[2]
                Assign("main" & $tvcount, GUICtrlCreateTreeViewItem($keytitle, $TreeView1), 2)
                x("reg." & Eval("main" & $tvcount) & ".name", $keytitle)
                x("reg." & Eval("main" & $tvcount) & ".path", $keypath)
                x("reg." & Eval("main" & $tvcount) & ".variable", "main" & $tvcount)
                $tvcount = $tvcount + 1
            Case $line = ""
                ; Blank line - ignore
        EndSelect
    WEnd
    GUISetState(@SW_SHOW)
    FileClose($configfile)
EndFunc   ;==>GetConfig

Func Treeview1($nMsg)
    Dim $tvcount = 0, $i, $c
    $type = ""
    GUICtrlSetData($Keyedit, "")
    GUICtrlSetData($valedit, "")
    GUICtrlSetData($datedit, "")
    ;MsgBox(0,"Message",$nMsg)
    _GUICtrlTreeView_BeginUpdate($TreeView1)

    $regkey = x("reg." & $nMsg & ".path")
    $title = x("reg." & $nMsg & ".title")
    $variable = x("reg." & $nMsg & ".variable")
    $type = x("reg." & $nMsg & ".type")

    If StringInStr($variable, "_val") Then
        ; Variable contained _val, so a value was clicked - need to edit it!!
        $data = x("reg." & $nMsg & ".data")
        _readvalue($nMsg)
    Else
        If StringInStr($variable, "hotkey") Then
            $nMsg = InsertHotkey($nMsg, $regkey, $title, $variable, $type)
            $regkey = x("reg." & $nMsg & ".path")
            $title = x("reg." & $nMsg & ".title")
            $variable = x("reg." & $nMsg & ".variable")
            $type = x("reg." & $nMsg & ".type")
        EndIf
        ; messy delete old data :(
        ; works, but has screen flash without the _GUICtrlTreeView_BeginUpdate($TreeView1) line
        GUICtrlSetState($nMsg, $TVE_COLLAPSE)

        $c = 1
        While 1
            $subkey = Eval("$variable$" & "_" & "$c$")
            $isdeclared = IsDeclared("$variable$" & "_" & "$c$")
            ;MsgBox(0,"$variable$_$c$", $subkey & @CRLF & $variable & @CRLF & "Delcared? " & $isdeclared & @CRLF & "$variable$" & "_" & "$c$")
            If IsInt($subkey) Then
                GUICtrlDelete($subkey)
            Else
                ExitLoop
            EndIf
            $c = $c + 1
        WEnd

        ; Start creating the sub-keys of the Item clicked on.
        $c = 1
        While 1
            $key = RegEnumKey($regkey, $c)
            If $key = "" Then ExitLoop
            $path = $regkey & "\" & $key
            $title = $key
            Assign("$variable$" & "_" & "$c$", GUICtrlCreateTreeViewItem($key, $nMsg), 2)
            x("reg." & Eval("$variable$" & "_" & "$c$") & ".path", $path)
            x("reg." & Eval("$variable$" & "_" & "$c$") & ".title", $title)
            x("reg." & Eval("$variable$" & "_" & "$c$") & ".variable", $variable & "_" & $c)
            $c = $c + 1
        WEnd

        ; Display the Values and data of the hilighted key name

        _GUICtrlListView_DeleteAllItems($ListView1)
        $c = 1
        SetError(0)
        While 1
            $val = RegEnumVal($regkey, $c)
            If @error <> 0 Then ExitLoop
            $type = @extended
            If $val = "" Then
                $val = "(Default)"
            EndIf

            Switch $type
                Case 1
                    $typedisp = "REG_SZ"
                Case 2
                    $typedisp = "REG_EXPAND_SZ"
                Case 3
                    $typedisp = "REG_BINARY"
                Case 4
                    $typedisp = "REG_DWORD"
                Case 5
                    $typedisp = "REG_DWORD_BIG_ENDIAN"
                Case 6
                    $typedisp = "REG_LINK"
                Case 7
                    $typedisp = "REG_MULTI_SZ"
                Case 8
                    $typedisp = "REG_RESOURCE_LIST"
                Case 9
                    $typedisp = "REG_FULL_RESOURCE_DESCRIPTOR"
                Case 10
                    $typedisp = "REG_RESOURCE_REQUIREMENTS_LIST"
            EndSwitch

            $data = RegRead($regkey, $val)
            If $data = "" Then
                $data = "value not set"
            EndIf
            Assign("$variable$" & "_val" & "$c$", GUICtrlCreateListViewItem($val & "|" & $typedisp & "|" & $data, $ListView1))
            x("reg." & Eval("$variable$" & "_val" & "$c$") & ".path", $regkey)
            x("reg." & Eval("$variable$" & "_val" & "$c$") & ".title", $val)
            x("reg." & Eval("$variable$" & "_val" & "$c$") & ".type", $type)
            x("reg." & Eval("$variable$" & "_val" & "$c$") & ".typedisp", $typedisp)
            x("reg." & Eval("$variable$" & "_val" & "$c$") & ".variable", $variable & "_val" & $c)
            x("reg." & Eval("$variable$" & "_val" & "$c$") & ".data", $data)
            $c = $c + 1
            $type = ""
        WEnd

    EndIf

    ; Show the results

    _GUICtrlTreeView_EndUpdate($TreeView1)
    GUICtrlSetState($nMsg, $GUI_EXPAND)
    GUISetState(@SW_SHOW)
    ;x_display()
EndFunc   ;==>Treeview1

Func _readvalue($nMsg)
    ;MsgBox(0, "need to read", "gotta figure this out, nMsg = " & $nMsg)
    ; its a value that correpsonds to an reg entry in the assoiative array
    $i = $nMsg
    $regkey = x("reg." & $i & ".path")
    $title = x("reg." & $i & ".title")
    $variable = x("reg." & $i & ".variable")
    $type = x("reg." & $i & ".typedisp")
    $data = x("reg." & $i & ".data")
    ; put into an array to check for changes
    ; 0 = 6, 1 = path, 2 = title, 3 = type, 4 = typedisp, 5 = data, 6 = variable
    $valarray[0] = 6
    $valarray[1] = $regkey
    $valarray[2] = $title
    $valarray[3] = x("reg." & $i & ".type")
    $valarray[4] = $type
    $valarray[5] = $data
    $valarray[6] = $variable

    ; set the input box data
    GUICtrlSetData($valedit, $title)
    GUICtrlSetData($TypeCombo,"|REG_SZ|REG_EXPAND_SZ|REG_BINARY|REG_DWORD|REG_DWORD_BIG_ENDIAN|REG_LINK|REG_MULTI_SZ|REG_RESOURCE_LIST|REG_FULL_RESOURCE_DESCRIPTOR|REG_RESOURCE_REQUIREMENTS_LIST",$type)
    GUICtrlSetData($datedit, $data)
EndFunc   ;==>_readvalue

Func _readkeys($nMsg)
    $readvalue = _GUICtrlTreeView_GetText($TreeView1, $nMsg)
    MsgBox(0, "Testing", $readvalue)
    x_display()
    $i = 0
    While 1
        $i = $i + 1
        $test = x("reg." & $i & ".title")
        If StringInStr($test, $readvalue) Then
            ;
            ExitLoop
        EndIf
    WEnd
    $regkey = x("reg." & $i & ".path")
    $title = x("reg." & $i & ".title")
    $variable = x("reg." & $i & ".variable")
    $nMsg = $i
    ;MsgBox(0,"Testing",$nMsg & " :: " & $regkey & " :: " & $title & " :: " & $variable & " :: " & $type)
    ; put into an array to check for changes
    ; 0 = 3, 1 = path, 2 = title, 3 = variable
    $keyarray[0] = 3
    $keyarray[1] = $regkey
    $keyarray[2] = $title
    $keyarray[3] = $variable
    GUICtrlSetData($Keyedit, $title)
EndFunc ;==>_readkey

Func _placeholder()
    ; set up editing buttons
    ; check to see if it is a key or a value that is being edited.
    ; $i is the key id number for the associative array.  So reg.$i.variable will tell us where it is
    ; in the tree.

    ; set up the right buttons

    ; delete key button

    ; delete value button

    ; save changes to value button

    ; add a value to the key

EndFunc   ;==>_placeholder

Func InsertHotkey($nMsg, $regkey, $title, $variable, $type)
    ;MsgBox(0,"Getting here","InsertHotkey function start")
    Assign("$variable$" & "_" & "HK", GUICtrlCreateTreeViewItem($title, $TreeView1), 2)
    ;If $computername <> @ComputerName Then
    ;   $regkey = "\\" & $computername & "\" & $regkey
    ;EndIf
    Dim $c = 1
    While 1
        $key = RegEnumKey($regkey, $c)
        If $key = "" Then ExitLoop
        $path = $regkey & "\" & $key
        $title = $key
        Assign("$title$" & "_" & "$c$", GUICtrlCreateTreeViewItem($key, Eval("$variable$" & "_" & "HK")), 2)
        x("reg." & Eval("$title$" & "_" & "$c$") & ".path", $path)
        x("reg." & Eval("$title$" & "_" & "$c$") & ".title", $title)
        x("reg." & Eval("$title$" & "_" & "$c$") & ".variable", $title & "_" & $c)
        $c = $c + 1
    WEnd
    Return (Eval("$variable$" & "_" & "$c$"))
EndFunc   ;==>InsertHotkey

Func Connectto()
    $computername = InputBox("Connect To :", "Computer Name : ")
    GUICtrlSetData($pclabel, $computername)
    _TreeView_DeleteAll($TreeView1)
    GetConfig()
EndFunc   ;==>Connectto

Func EditOptions()
    ShellExecuteWait("Notepad.exe", "bkconfig.ini")
    _TreeView_DeleteAll($TreeView1)
    GetConfig()
EndFunc   ;==>EditOptions

Func _TreeView_DeleteAll($handle)
    ; My Tree view... I know the handle variable naming convention. :D
    ; and why is there no "Collapse" function??
    _GUICtrlTreeView_BeginUpdate($handle)
    GUICtrlSetState($handle, $TVE_COLLAPSE)

    $c = 1
    While 1

        $subkey = Eval("main" & $c)
        $declared = IsDeclared("main" & $c)
        ;MsgBox(0,"testing","Delete All Treeview" & @CRLF & "Declared = " & $declared & @CRLF & "main$c$" & " " & $subkey)
        If IsDeclared("main" & $c) Then
            $subkey = Eval("main" & $c)
            GUICtrlSetState($subkey, $TVE_COLLAPSE)
            If IsInt($subkey) Then
                GUICtrlDelete($subkey)
            Else
                ExitLoop
            EndIf
        Else
            ExitLoop
        EndIf
        $c = $c + 1
    WEnd

    _GUICtrlTreeView_EndUpdate($TreeView1)
    GUICtrlSetState($nMsg, $GUI_EXPAND)
    GUISetState(@SW_SHOW)
EndFunc   ;==>_TreeView_DeleteAll
Edited by Graywalker
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...