Zinthose Posted May 10, 2011 Posted May 10, 2011 (edited) 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.FeaturesSupports 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_NONEREG_SZREG_EXPAND_SZREG_BINARYREG_DWORDREG_DWORD_BIG_ENDIANREG_LINKREG_MULTI_SZREG_RESOURCE_LISTREG_FULL_RESOURCE_DESCRIPTORREG_RESOURCE_REQUIREMENTS_LISTREG_QWORDCallBack Functions:_RegFileParser_FileOpen_RegFileParser_FileClose_RegFileParser_KeyDelete_RegFileParser_KeyNew_RegFileParser_ValueDelete_RegFileParser_ValueWriteExample:expandcollapse popup#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) EndFuncThis is my Alpha Release and it might have bugs but my tests look good so far. 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 May 12, 2011 by Zinthose --- TTFN
Zinthose Posted June 12, 2011 Author Posted June 12, 2011 28 downloads... either it works perfectly or is complete crap an no one wants to hurt my feelings... --- TTFN
jaberwacky Posted June 12, 2011 Posted June 12, 2011 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? Helpful Posts and Websites: AutoIt3 Variables and Function Parameters MHz | AutoIt Wiki | Using the GUIToolTip UDF BrewManNH | Can't find what you're looking for on the Forum?
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now