Converts .Reg Files to AU3.
Supports command line (When compiled)-
/INFILE- Specifies input .reg file. Leave blank to select a file using FileOpen
/OUTFILE- Specifies ouput .au3 file. Leave blank to copy AU3 output to clipboard.
/OVERWRITE- Only used when /OUTFILE is used. 0 = No Overwrite, will append to end of file, 1 = Overwrite, will clear file.
A 112MB reg file complete in just under 2 minutes. (2GB RAM, Intel Core 2 Duo 1.8GHz, Uncompiled.)
#include <GUIConstantsEx.au3> Dim $infile = "", $outfile = "", $output = "", $overwrite = False, $offset = 0, $post = "" ;Command line for if compiled If @Compiled And $CmdLineRaw Then $strings = StringSplit($CmdLineRaw, "/") For $i = 1 To $strings[0] $cmd = StringSplit($strings[$i], ' "', 1) If $cmd[0] <> 1 Then $param = StringReplace($cmd[1], '"', "") $param1 = StringReplace($cmd[2], '"', "") Switch $param Case "INFILE" $infile = $param1 Case "OUTFILE" $outfile = $param1 Case "OVERWRITE" If $param1 = 0 Then $overwrite = False If $param1 = 1 Then $overwrite = True EndSwitch EndIf Next EndIf ;If not compiled/no command line, ask user to select files If $infile = "" Then $infile = FileOpenDialog("Open Reg File", "", "Registry Files (*.reg)") If $infile = "" Then MsgBox(0, "", "Needs Input File!") Exit EndIf If $outfile = "" Then $outfile = FileSaveDialog("Save Output", "", "AutoIt V3 Scripts(*.au3)") ;If .au3 not on the end of outfile, add it. If StringRight($outfile, 4) <> ".au3" Then $outfile &= ".au3" ;Start Timer $timer = TimerInit() ;Read all Sections $var = IniReadSectionNames($infile) ;Set Totals for Progress $total1 = $var[0] $total2 = 0 ;Create GUI $Form1 = GUICreate("Reg2Au3", 230, 100, 193, 115) $Label1 = GUICtrlCreateLabel("", 8, 8, 214, 37) $Progress1 = GUICtrlCreateProgress(8, 52, 214, 17) GUICtrlSetLimit(-1, 100, 0) $Progress2 = GUICtrlCreateProgress(8, 76, 214, 17) GUICtrlSetLimit(-1, 100, 0) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### If @error Then MsgBox(4096, "Error", "Error getting sections.") Else For $i = 1 To $var[0] $var123 = StringReplace($var[$i], "'", "''") $text = $i & " /" & $total1 & " Sections Done - 1/1 Keys " & @CRLF & "Running for " & Round(TimerDiff($timer) / 1000, 2) & " seconds" GUICtrlSetData($Label1, $text) If GUIGetMsg() = -3 Then Exit $percent1 = Round(($i / $total1) * 100, 0) GUICtrlSetData($Progress1, $percent1) $section = IniReadSection($infile, $var[$i]) If @error Then $var123 = StringReplace($var123, "'", "''") $output &= "RegWrite ('" & $var123 & "')" & @CRLF Else $total2 = $section[0][0] For $a = 1 To $section[0][0] $text = $i & " /" & $total1 & " Sections Done - " & $a & "/" & $total2 & " Keys " & @CRLF & "Running for " & Round(TimerDiff($timer) / 1000, 2) & " seconds" GUICtrlSetData($Label1, $text) If GUIGetMsg() = -3 Then Exit $percent2 = Round(($a / $total2) * 100, 0) GUICtrlSetData($Progress2, $percent2) $key = StringReplace($section[$a][0], "@", "") $value = $section[$a][1] $type = "REG_SZ" $pos = StringInStr($value, ":") $str = StringLeft($value, $pos - 1) If @error <> 1 Then $type = $str If $type = "Hex" Then $type = "REG_BINARY" $value = StringReplace(StringTrimLeft($value, $pos), ",", "") ElseIf $type = "dword" Then $type = "REG_DWORD" $value = StringTrimLeft($value, $pos) ElseIf $type = "hex(7)" Then $type = "REG_MULTI_SZ" $value = StringTrimLeft($value, $pos) ElseIf $type = "hex(2)" Then $type = "REG_EXPAND_SZ" $value = StringTrimLeft($value, $pos) ElseIf $type = "hex(0)" Then $type = "REG_NONE" $value = StringTrimLeft($value, $pos) $post = ";" Else $type = "REG_SZ" EndIf EndIf If StringLeft($value, 1) = '"' Then $value = StringTrimLeft($value, 1) If StringRight($value, 1) = '"' Then $value = StringTrimRight($value, 1) $value = StringReplace($value, "'", "''") $key = StringReplace($key, "'", "''") $var123 = StringReplace($var123, "'", "''") If $type = "" Then $type = "" ElseIf $key = "" Then $key = "" EndIf $output &= $post & "RegWrite ('" & $var123 & "', '" & $key & "', '" & $type & "', '" & $value & "')" & @CRLF $post = "" Next EndIf Next EndIf ;No outfile then paste to clipboard If $outfile = "" Then ClipPut($output) Else If $overwrite = True Then $offset = 10 $file = FileOpen($outfile, 2 + $offset) FileWrite($file, $output) FileClose($file) EndIf GUIDelete($Form1) MsgBox(0, "Complete!", "Process completed in " & Round(TimerDiff($timer) / 1000, 2) & "seconds")
Probably a one off release, I hope it helps someone- whether its parsing Reg files, or acutally using it to help in scripts.
Cheers,
Brett
Edited by BrettF, 13 October 2008 - 04:21 AM.




