Jump to content

RegFileParser


Zinthose
 Share

Recommended Posts

I wanted to be able to parse .reg files for inclusion into my own scripts or trans-coding into other scripting formats. I've found the regular expressions in AutoIt to be a perfect fit. I tried to make this match as closely to a manual .reg file import as possible.

The library has one public function and will use callbacks to let you know what it found.

Features

  • Supports both the "REGEDIT4" and "Window's Registry Editor Version 5.00" file formats.
  • Accepts 3 different file list formats:
    • Single file - "C:\MyPath\RegToImport_HKLM.reg"
    • FileOpenDialog - Ex. "C:\MyPath|RegToImport_HKLM.reg|RegToImport_HKCU.reg"
    • Comma Delimited - Ex. "C:\MyPath\RegToImport_HKLM.reg,C:\MyPath\RegToImport_HKCU.reg"
  • Supports all the following registry types:
    • REG_NONE
    • 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_QWORD
  • CallBack Functions:
    • _RegFileParser_FileOpen
    • _RegFileParser_FileClose
    • _RegFileParser_KeyDelete
    • _RegFileParser_KeyNew
    • _RegFileParser_ValueDelete
    • _RegFileParser_ValueWrite

Example:

#include <Array.au3>
    #include "RegFileParser.au3
    $Files = FileOpenDialog("Import Registry Files", @WorkingDir, "Windows Registry Files (*.reg)", 7)

    Dim $return = _RegFileParser_RegParse($Files, 5)
    Dim $err[2] = [@error, @extended]

    MSG("$return="   & $return, "!")
    MSG("@error="      & $err[0], "!")
    MSG("@extended=" & $err[1], "!")

    ;## CallBack Functions
        Func _RegFileParser_DEBUG($Message)
            MSG($Message, "!")
        EndFunc

        Func _RegFileParser_FileOpen($File_Path, $File_Type)
            MSG('_RegFileParser_FileOpen')
            MSG('       $File_Path  := "' & $File_Path & '"', ">")
            MSG('       $File_Type  := ' & $File_Type, ">")
        EndFunc

        Func _RegFileParser_FileClose($File_Path)
            MSG('_RegFileParser_FileClose')
            MSG('       $File_Path  := "' & $File_Path & '"', ">")
        EndFunc

        Func _RegFileParser_KeyDelete($HKEY_Path)
            If IsArray($HKEY_Path) Then $HKEY_Path = _ArrayToString($HKEY_Path, "\")
            MSG('_RegFileParser_KeyDelete')
            MSG('       $HKEY_Path  := "' & $HKEY_Path & '"', ">")
        EndFunc

        Func _RegFileParser_KeyNew($HKEY_Path)
            If IsArray($HKEY_Path) Then $HKEY_Path = _ArrayToString($HKEY_Path, "\")
            MSG('_RegFileParser_KeyNew')
            MSG('       $HKEY_Path  := "' & $HKEY_Path & '"', ">")
        EndFunc

        Func _RegFileParser_ValueDelete($HKEY_Path, $ValueName)
            If IsArray($HKEY_Path) Then $HKEY_Path = _ArrayToString($HKEY_Path, "\")
            MSG('_RegFileParser_ValueDelete')
            MSG('       $HKEY_Path  := "' & $HKEY_Path & '"', ">")
            MSG('       $ValueName  := "' & $ValueName & '"', ">")
        EndFunc

        Func _RegFileParser_ValueWrite($HKEY_Path, $ValueName, $Value, $ValueType)
            If IsArray($HKEY_Path) Then $HKEY_Path = _ArrayToString($HKEY_Path, "\")
            If IsArray($Value) Then $Value = _ArrayToString($Value, "|")
            MSG('_RegFileParser_ValueWrite')
            MSG('       $HKEY_Path  := "' & $HKEY_Path & '"', ">")
            MSG('       $ValueName  := "' & $ValueName & '"', ">")
            MSG('       $Value      := "' & $Value & '"', ">")
            MSG('       $ValueType  := "' & $ValueType & '"', ">")
        EndFunc

    ;## Just a wrapper for ConsoleWriteError
        Func MSG($Message, $Level = "+")
            ConsoleWriteError($Level & " " & $Message & @CRLF)
        EndFunc

This is my Alpha Release and it might have bugs but my tests look good so far. :unsure:

  • 2011-05-12 19:07 - Corrected a few bugs, renamed main function from "_RegParse" to "_RegFileParser_RegParse" to closer match common naming conventions., added a new function "_RegFileParser_BinaryToValue" to permit decoding binary values into intend REG_* data types.

RegFileParser.au3

Edited by Zinthose

--- TTFN

Link to comment
Share on other sites

  • 1 month later...

With this registry file:

Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Control Panel\Desktop]
"ActiveWndTrackTimeout"=dword:00000096
"UserPreferencesMask"=hex:9f,3e,07,80,12,00,00,00

I got this output:

+ _RegFileParser_FileOpen
>       $File_Path  := "D:\Programs - Uninstalled\Hover window select.reg"
>       $File_Type  := 5
! Header line detected
+ _RegFileParser_KeyNew
>       $HKEY_Path  := "HKEY_CURRENT_USER\Control Panel\Desktop"
+ _RegFileParser_ValueWrite
>       $HKEY_Path  := "HKEY_CURRENT_USER\Control Panel\Desktop"
>       $ValueName  := "ActiveWndTrackTimeout"
>       $Value      := "150"
>       $ValueType  := "REG_DWORD"
! Data line Detected: DWORD
! HEX Value detected as REG_BINARY
+ _RegFileParser_ValueWrite
>       $HKEY_Path  := "HKEY_CURRENT_USER\Control Panel\Desktop"
>       $ValueName  := "UserPreferencesMask"
>       $Value      := "0x9F3E078012000000"
>       $ValueType  := "REG_BINARY"
+ _RegFileParser_FileClose
>       $File_Path  := "D:\Programs - Uninstalled\Hover window select.reg"
! $return=0
! @error=0
! @extended=0

Is this expected behavior?

Link to comment
Share on other sites

  • 2 weeks later...

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...