Dan Posted April 8, 2004 Share Posted April 8, 2004 (edited) I often use autoit for simple configuration/installation tasks including copying files, making registry changes etc. I used it to install an application today and found the little app required 130+ reg keys. i simply exported the pertinent registry sections to file then used file install(@tempdir... and run("regedit.... to import the registry. There were about 25 keys that were dynamic, windows directory, etc, so i had to write these keys from an au3 script with regwrite commands; way too much work. So, i banged out this script to convert a .reg file to an .au3 file which can then be included, copied into main script,.... It could be cleaned up and improved, but it met my needs and i thought it might be of some use to others, so here you go. DanMake sure when exporting registry files from 2000/xp that you choose Win9x/NT4 Registration file type when saving.expandcollapse popup;version .25 - lines begining with; are treated as comments and written to output file. ;Version .24 - Fixed issue with REG_MULTI_SZ AutoItSetOption("MustDeclareVars", 1) ;AutoItSetOption("TrayIconDebug", 1) Dim $REGFILE, $INFILE, $OUTFILE, $TEXT, $KEY, $VALUE, $VALUEDATA, $VALUETYPE OpenFiles() ParseFile() Func OpenFiles() $REGFILE = FileOpenDialog("Choose .REG file",@DesktopDir, "Registry Files (*.reg)") If $REGFILE = 1 Then Exit EndIf $INFILE = FileOpen($REGFILE, 0) $OUTFILE = FileOpen(StringTrimRight($REGFILE,4) & ".au3",1);output file is changed from .reg to .au3 (ie: office.reg will be saved as office.au3) If $OUTFILE = -1 Then ProgramExit("Output File Error|Error opening " & StringTrimRight($REGFILE,4) & ".au3",1) EndIf If $INFILE = -1 Then ProgramExit("Input File Error|Error opening " & $REGFILE,1) EndIf ;read first line of file to confirm it is a regedit4 file $TEXT = FileReadLine($INFILE) If Not StringInStr($TEXT, "REGEDIT4") Then ProgramExit("Error Opening .REG file|" & $REGFILE & " does not appear to be a valid Regedit4 formatted registry file.",1) EndIf EndFunc ;==>OpenFiles Func ParseFile() Dim $TEMP $TEXT =FileReadLine($INFILE) While $TEXT = "" $TEXT = FileReadLine($INFILE) Wend While 1 While StringLeft($TEXT,1) = ";";ignore comment and read next line FileWriteLine($OUTFILE,$TEXT) $TEXT = FileReadLine($INFILE);get next line Wend If StringLeft($TEXT,1) = "[" And StringRight($TEXT, 1) = "]" Then;Brackets at each end. found a key $KEY = StringMid($TEXT,2,StringLen($TEXT)-2); parse string for key name $TEXT = FileReadLine($INFILE);get next line EndIf While StringLeft($TEXT,1) <> "[" And StringRight($TEXT, 1) <> "]" And $TEXT <> "";read values until we see another key. While StringLeft($TEXT,1) = ";";ignore comment and read next line FileWriteLine($OUTFILE,$TEXT) $TEXT = FileReadLine($INFILE);get next line Wend While StringRight($TEXT,1) = "\";Join lines split by regedit export $TEXT = StringTrimRight($TEXT,1) $TEXT = $TEXT & FileReadLine($INFILE) Wend $TEMP = StringSplit($TEXT, "=");split line into value and valuedata $VALUE = TrimQuote($TEMP[1]);remove quotes $VALUE = StringReplace($VALUE,"\\","\");reg file backslashes are \\ replace with \ If $VALUE = "@" Then ;change to autoit format for default value $VALUE = "" EndIf If StringInStr($TEMP[2],"hex:") Then $VALUETYPE = "REG_BINARY" $VALUEDATA = StringTrimLeft($TEMP[2],StringInStr($TEMP[2],"hex:")+3) ;Remove spaces and commas to properly format binary value $VALUEDATA = StringReplace($VALUEDATA," ","") $VALUEDATA = StringReplace($VALUEDATA,",","") ElseIf StringInStr($TEMP[2],"hex(2):") Then $VALUETYPE = "REG_EXPAND_SZ" $VALUEDATA = CharsToString(StringTrimLeft($TEMP[2],StringInStr($TEMP[2],"hex(2):")+6)) ElseIf StringInStr($TEMP[2],"hex(7):") Then $VALUETYPE = "REG_MULTI_SZ" $VALUEDATA = CharsToString(StringTrimLeft($TEMP[2],StringInStr($TEMP[2],"hex(7):")+6)) ElseIf StringInStr($TEMP[2],"dword:") Then $VALUETYPE = "REG_DWORD" $VALUEDATA = StringTrimLeft($TEMP[2],StringInStr($TEMP[2],"dword:")+5) Else $VALUETYPE = "REG_SZ" $VALUEDATA = TrimQuote($TEMP[2]) $VALUEDATA = StringReplace($VALUEDATA,'\"','"');reg file quotes are \" replace with quote $VALUEDATA = StringReplace($VALUEDATA,"\\","\");reg file backslashes are \\ replace with \ $VALUEDATA = StringReplace($VALUEDATA,"'","''");regstring in output file enclose with single quotes. make sure single quotes in string are output EndIf If $VALUETYPE = "REG_MULTI_SZ" Then FileWriteLine($OUTFILE,'RegWrite(' & DblQuote($KEY) & "," & DblQuote($VALUE) & "," & DblQuote($VALUETYPE) & "," & DblQuote($VALUEDATA) & ')') Else FileWriteLine($OUTFILE,'RegWrite(' & DblQuote($KEY) & "," & DblQuote($VALUE) & "," & DblQuote($VALUETYPE) & "," & SingleQuote($VALUEDATA) & ')') EndIf $TEXT = FileReadLine($INFILE) If @error <> 0 Then ExitLoop EndIf Wend $TEXT = FileReadLine($INFILE) If @error <> 0 Then ExitLoop EndIf Wend ProgramExit("Operation Complete|Input File: " & $REGFILE & @CR & "Output File: "& StringTrimRight($REGFILE,4) & ".au3",0) EndFunc ;==>ParseFile Func TrimQuote($INSTRING) ;remove leading and trailing quotes If StringLeft($INSTRING,1) = '"' Then $INSTRING= StringTrimLeft($INSTRING,1) EndIf If StringRight($INSTRING,1) = '"' Then $INSTRING = StringTrimRight($INSTRING, 1) EndIf Return $INSTRING EndFunc ;==>TrimQuote Func CharsToString($INSTRING) Dim $TEMPARRAY, $COUNT $INSTRING = StringReplace($INSTRING," ","") ;Remove trailing nulls While StringRight($INSTRING,3) = ",00" $INSTRING = StringTrimRight($INSTRING,3) Wend ;Create an array of character values and build string $TEMPARRAY = StringSplit($INSTRING, ",") $INSTRING = "" For $COUNT = 1 To $TEMPARRAY[0] If $TEMPARRAY[$COUNT] = "00" Then $INSTRING = $INSTRING & '" & @LF & "';separate items with linefeed character Else $INSTRING = $INSTRING & Chr(Dec($TEMPARRAY[$COUNT]));convert hex to dec then get character value and append to return string EndIf Next Return $INSTRING EndFunc ;==>CharsToString Func DblQuote($INSTRING) $INSTRING = Chr(34) & $INSTRING & Chr(34) Return $INSTRING EndFunc ;==>DblQuote Func SingleQuote($INSTRING) $INSTRING = Chr(39) & $INSTRING & Chr(39) Return $INSTRING EndFunc ;==>SingleQuote Func ProgramExit($INSTRING,$ERROR) Dim $FLAGS,$TEMPARRAY If $ERROR = 1 Then $FLAGS = 16 Else $FLAGS = 64 EndIf $TEMPARRAY = StringSplit($INSTRING, "|") MsgBox($FLAGS, $TEMPARRAY[1], $TEMPARRAY[2]) If $INFILE <> -1 Then FileClose($INFILE) EndIf If $OUTFILE <> -1 Then FileClose($OUTFILE) EndIf Exit EndFunc ;==>ProgramExit Edited June 8, 2004 by Dan Link to comment Share on other sites More sharing options...
Guest rathore Posted April 8, 2004 Share Posted April 8, 2004 still to check it out, but i know it'll b damn usable...i've a similar script i made in AU2, it lacked binary values due to deficiency in AU2. so i was going to port it to AU3... but thanx to u, i won't have to do it now!! Link to comment Share on other sites More sharing options...
Guest rathore Posted April 8, 2004 Share Posted April 8, 2004 checked now... works fine until it finds a multiline reg binary value. try this .reg file: REGEDIT4 [HKEY_CURRENT_USER\Software\Helios\TextPad 4\Document Classes\AutoIt v3] "Type"=dword:00000002 "Members"=hex(7):2a,2e,61,75,33,00,00 "Properties"=hex:2a,00,2e,00,61,00,75,00,33,00,00,00,00,00 "SyntaxProps"=hex:01,00,00,00 "SyntaxFile"="autoit_v3.syn" "WordChars"="_$" "Colors"=hex:01,00,00,00,01,00,00,00,01,00,00,00,01,00,00,00,01,00,00,00,01,00,\ 00,00,01,00,00,00,01,00,00,00,01,00,00,00,01,00,00,00,01,00,00,00,01,00,00,\ 00,01,00,00,00,01,00,00,00,01,00,00,00,01,00,00,00,69,13,b0,00,01,00,00,00,\ 01,00,00,00,01,00,00,00,01,00,00,00,01,00,00,00,01,00,00,00,01,00,00,00,01,\ 00,00,00,01,00,00,00,01,00,00,00,01,00,00,00,01,00,00,00,01,00,00,00,01,00,\ 00,00,01,00,00,00,01,00,00,00,01,00,00,00,01,00,00,00,01,00,00,00,01,00,00,\ 00,01,00,00,00,01,00,00,00,01,00,00,00,01,00,00,00,01,00,00,00,01,00,00,00,\ 01,00,00,00 Link to comment Share on other sites More sharing options...
Guest rathore Posted April 8, 2004 Share Posted April 8, 2004 (edited) works fine, just needed a li'l correction! line 55 has: $VALUEDATA = StringReplace($VALUEDATA," ","") insert new line after it: $VALUEDATA = StringReplace($VALUEDATA,",","") thanx and congrats on this nice script. most ppl will never need it, but who does knows its value! edit: i first thought line 55 has to be replaced by my correction, but no, the correction needs to be added after line 55. Edited April 8, 2004 by rathore Link to comment Share on other sites More sharing options...
ZenKensei Posted April 8, 2004 Share Posted April 8, 2004 Rathore, Dan; Any chance of getting the corrected script noted below posted as a response. I see the remark about replacing the 'if' statement with 'while' and Dan's correction/addition to the stringreplace after line 55. With the massive number of if statesments I'm somewhat unsure about which 'if' statement needs replacing by 'while'. Thanks, Z/K Link to comment Share on other sites More sharing options...
Dan Posted April 8, 2004 Author Share Posted April 8, 2004 The code was updated with all changes identified in this thread. If you find more issues, let me know. Link to comment Share on other sites More sharing options...
this-is-me Posted April 8, 2004 Share Posted April 8, 2004 (edited) If there is a REG_SZ path in the registry like C:\Windows It comes out in the .reg file as C:\\Windows when exported (double backslash) This is not fixed in your code. You will also need to fix double quotation marks" comes out as \" (backslash before) By the way, good code. Edited April 8, 2004 by this-is-me Who else would I be? Link to comment Share on other sites More sharing options...
Guest rathore Posted April 8, 2004 Share Posted April 8, 2004 this is not fixed correctly Dan, $VALUEDATA = StringReplace($VALUEDATA," ","") $VALUEDATA = StringReplace($VALUEDATA,", ","") the 'space' should go, it should be like: $VALUEDATA = StringReplace($VALUEDATA," ","") $VALUEDATA = StringReplace($VALUEDATA,",","") i'll check the bug pointed out by this-is-me Link to comment Share on other sites More sharing options...
Dan Posted April 8, 2004 Author Share Posted April 8, 2004 (edited) Fixed the issues idenfied by rathore and this-is-me. Thanks for the help guys. If you find anything else, let me know. Edited April 8, 2004 by Dan Link to comment Share on other sites More sharing options...
Guest rathore Posted April 8, 2004 Share Posted April 8, 2004 oops! ...try this: expandcollapse popupREGEDIT4 [HKEY_CLASSES_ROOT\Winamp.File] @="Winamp media file" [HKEY_CLASSES_ROOT\Winamp.File\DefaultIcon] @="e:\\Program Files\\Winamp\\Winamp.exe,1" [HKEY_CLASSES_ROOT\Winamp.File\shell] @="Play" [HKEY_CLASSES_ROOT\Winamp.File\shell\Enqueue] @="&Enqueue in Winamp" [HKEY_CLASSES_ROOT\Winamp.File\shell\Enqueue\command] @="\"e:\\Program Files\\Winamp\\Winamp.exe\" /ADD \"%1\"" [HKEY_CLASSES_ROOT\Winamp.File\shell\Enqueue\DropTarget] "Clsid"="{77A366BA-2BE4-4a1e-9263-7734AA3E99A2}" [HKEY_CLASSES_ROOT\Winamp.File\shell\ListBookmark] @="Add to Winamp's &Bookmark list" [HKEY_CLASSES_ROOT\Winamp.File\shell\ListBookmark\command] @="\"e:\\Program Files\\Winamp\\Winamp.exe\" /BOOKMARK \"%1\"" [HKEY_CLASSES_ROOT\Winamp.File\shell\open] @="" [HKEY_CLASSES_ROOT\Winamp.File\shell\open\command] @="\"e:\\Program Files\\Winamp\\Winamp.exe\" \"%1\"" [HKEY_CLASSES_ROOT\Winamp.File\shell\open\DropTarget] "Clsid"="{46986115-84D6-459c-8F95-52DD653E532E}" [HKEY_CLASSES_ROOT\Winamp.File\shell\Play] @="&Play in Winamp" [HKEY_CLASSES_ROOT\Winamp.File\shell\Play\command] @="\"e:\\Program Files\\Winamp\\Winamp.exe\" \"%1\"" [HKEY_CLASSES_ROOT\Winamp.File\shell\Play\DropTarget] "Clsid"="{46986115-84D6-459c-8F95-52DD653E532E}" Link to comment Share on other sites More sharing options...
Dan Posted April 9, 2004 Author Share Posted April 9, 2004 Ok. I added some code to deal with escaped characters (" and \). Let me know if you find anything else. Link to comment Share on other sites More sharing options...
Guest rathore Posted April 9, 2004 Share Posted April 9, 2004 (edited) sorry to bother Dan but the '\' in value also needs to be rectified. try this: expandcollapse popupREGEDIT4 [HKEY_CURRENT_USER\Software\Wonderful Icon\Version 1.5\AutoChange] "SystemStart"=hex:00,00,00,00,00,01,00,00,2e,5c,00 ".Default"=hex:00,00,00,00,00,01,00,00,2e,5c,00 "SystemExit"=hex:00,00,00,00,00,01,00,00,2e,5c,00 "SystemHand"=hex:00,00,00,00,00,01,00,00,2e,5c,00 "SystemQuestion"=hex:00,00,00,00,00,01,00,00,2e,5c,00 "SystemExclamation"=hex:00,00,00,00,00,01,00,00,2e,5c,00 "SystemAsterisk"=hex:00,00,00,00,00,01,00,00,2e,5c,00 "Open"=hex:00,00,00,00,00,01,00,00,2e,5c,00 "Close"=hex:00,00,00,00,00,01,00,00,2e,5c,00 "Maximize"=hex:00,00,00,00,00,01,00,00,2e,5c,00 "Minimize"=hex:00,00,00,00,00,01,00,00,2e,5c,00 "RestoreDown"=hex:00,00,00,00,00,01,00,00,2e,5c,00 "RestoreUp"=hex:00,00,00,00,00,01,00,00,2e,5c,00 "AppGPFault"=hex:00,00,00,00,00,01,00,00,2e,5c,00 "MenuCommand"=hex:00,00,00,00,00,01,00,00,2e,5c,00 "MenuPopup"=hex:00,00,00,00,00,01,00,00,2e,5c,00 "MailBeep"=hex:00,00,00,00,00,01,00,00,2e,5c,00 "CCSelect"=hex:00,00,00,00,00,01,00,00,2e,5c,00 "ShowBand"=hex:00,00,00,00,00,01,00,00,2e,5c,00 "RingIn"=hex:00,00,00,00,00,01,00,00,2e,5c,00 "Ringout"=hex:00,00,00,00,00,01,00,00,2e,5c,00 "SystemDefault"=hex:00,00,00,00,00,01,00,00,2e,5c,00 "Explorer\\EmptyRecycleBin"=hex:00,00,00,00,00,01,00,00,2e,5c,00 "Explorer\\ActivatingDocument"=hex:00,00,00,00,00,01,00,00,2e,5c,00 "Explorer\\Navigating"=hex:00,00,00,00,00,01,00,00,2e,5c,00 "Explorer\\MoveMenuItem"=hex:00,00,00,00,00,01,00,00,2e,5c,00 "SndRec32\\Open"=hex:00,00,00,00,00,01,00,00,2e,5c,00 "SndRec32\\Close"=hex:00,00,00,00,00,01,00,00,2e,5c,00 "MPlayer\\Open"=hex:00,00,00,00,00,01,00,00,2e,5c,00 "MPlayer\\Close"=hex:00,00,00,00,00,01,00,00,2e,5c,00 "Conf\\Receive Call"=hex:00,00,00,00,00,01,00,00,2e,5c,00 "Conf\\Receive Request to Join"=hex:00,00,00,00,00,01,00,00,2e,5c,00 "Conf\\Person Joins"=hex:00,00,00,00,00,01,00,00,2e,5c,00 "Conf\\Person Leaves"=hex:00,00,00,00,00,01,00,00,2e,5c,00 "**Desktop Wallpaper"=hex:00,00,00,00,00,01,00,00,2e,5c,00 "Office97\\Office97-Reminder"=hex:00,00,00,00,00,01,00,00,2e,5c,00 "NMain-MouseOver"=hex:00,00,00,00,00,01,00,00,2e,5c,00 "NMain-MouseClick"=hex:00,00,00,00,00,01,00,00,2e,5c,00 "NMain-MouseLeave"=hex:00,00,00,00,00,01,00,00,2e,5c,00 "MSDev\\MSVC_OutputError"=hex:00,00,00,00,00,01,00,00,2e,5c,00 "MSDev\\MSVC_OutputWarning"=hex:00,00,00,00,00,01,00,00,2e,5c,00 "MSDev\\BuildError"=hex:00,00,00,00,00,01,00,00,2e,5c,00 "MSDev\\BuildWarning"=hex:00,00,00,00,00,01,00,00,2e,5c,00 "MSDev\\BuildComplete"=hex:00,00,00,00,00,01,00,00,2e,5c,00 "MSDev\\MSVC_HitBP"=hex:00,00,00,00,00,01,00,00,2e,5c,00 "PowerCfg\\LowBatteryAlarm"=hex:00,00,00,00,00,01,00,00,2e,5c,00 "PowerCfg\\CriticalBatteryAlarm"=hex:00,00,00,00,00,01,00,00,2e,5c,00 "WirelessLink\\InfraredInRange"=hex:00,00,00,00,00,01,00,00,2e,5c,00 "WirelessLink\\InfraredOutOfRange"=hex:00,00,00,00,00,01,00,00,2e,5c,00 "WirelessLink\\InfraredInterrupt"=hex:00,00,00,00,00,01,00,00,2e,5c,00 "MSMSGS\\New Message"=hex:00,00,00,00,00,01,00,00,2e,5c,00 "MSMSGS\\Contact Online"=hex:00,00,00,00,00,01,00,00,2e,5c,00 "MSMSGS\\New Mail"=hex:00,00,00,00,00,01,00,00,2e,5c,00 "CriticalBatteryAlarm"=hex:00,00,00,00,00,01,00,00,2e,5c,00 "DeviceConnect"=hex:00,00,00,00,00,01,00,00,2e,5c,00 "DeviceDisconnect"=hex:00,00,00,00,00,01,00,00,2e,5c,00 "DeviceFail"=hex:00,00,00,00,00,01,00,00,2e,5c,00 "LowBatteryAlarm"=hex:00,00,00,00,00,01,00,00,2e,5c,00 "PrintComplete"=hex:00,00,00,00,00,01,00,00,2e,5c,00 "SystemNotification"=hex:00,00,00,00,00,01,00,00,2e,5c,00 "WindowsLogoff"=hex:00,00,00,00,00,01,00,00,2e,5c,00 "WindowsLogon"=hex:00,00,00,00,00,01,00,00,2e,5c,00 "MPlay32\\Close"=hex:00,00,00,00,00,01,00,00,2e,5c,00 "MPlay32\\Open"=hex:00,00,00,00,00,01,00,00,2e,5c,00 "MSMSGS\\MSMSGS_ContactOnline"=hex:00,00,00,00,00,01,00,00,2e,5c,00 "MSMSGS\\MSMSGS_NewAlert"=hex:00,00,00,00,00,01,00,00,2e,5c,00 "MSMSGS\\MSMSGS_NewMail"=hex:00,00,00,00,00,01,00,00,2e,5c,00 "MSMSGS\\MSMSGS_NewMessage"=hex:00,00,00,00,00,01,00,00,2e,5c,00 "Dialer\\Incoming call"=hex:00,00,00,00,00,01,00,00,2e,5c,00 btw this is my 100th post, making me an adv member! Edited April 9, 2004 by rathore Link to comment Share on other sites More sharing options...
Dan Posted April 9, 2004 Author Share Posted April 9, 2004 rathore, 100 posts, but 30 of them were here finding bugs in my code. It looks like the issue was resolved in the data section, but still existed in the key name. I got that fixed, waiting for you to find something else. Link to comment Share on other sites More sharing options...
Guest rathore Posted April 9, 2004 Share Posted April 9, 2004 Hey Dan, i'd also fixed that error i mentioned. came online to post it and found u've already posted the corrected script. i've made it comprehensive and make it look for all the stuff there cud be (just like in valuedata). have a look (i've commented the changes i made). but there's some problem that makes the script throw some characters by itself to this .reg file. (it has not appeared after i made the changes!!) don't hate me !!! i'm not PUTTING these bugs, i'm just helping u remove them! expandcollapse popup;Version .21 - Should now correctly deal with \ and " characters in string values. AutoItSetOption("MustDeclareVars", 1) ;AutoItSetOption("TrayIconDebug", 1) Dim $REGFILE, $INFILE, $OUTFILE, $TEXT, $KEY, $VALUE, $VALUEDATA, $VALUETYPE OpenFiles() ParseFile() Func OpenFiles() $REGFILE = FileOpenDialog("Choose .REG file",@DesktopDir, "Registry Files (*.reg)") If $REGFILE = 1 Then Exit EndIf $INFILE = FileOpen($REGFILE, 0) $OUTFILE = FileOpen(StringTrimRight($REGFILE,4) & ".au3",1);output file is changed from .reg to .au3 (ie: office.reg will be saved as office.au3) If $OUTFILE = -1 Then ProgramExit("Output File Error|Error opening " & StringTrimRight($REGFILE,4) & ".au3",1) EndIf If $INFILE = -1 Then ProgramExit("Input File Error|Error opening " & $REGFILE,1) EndIf ;read first line of file to confirm it is a regedit4 file $TEXT = FileReadLine($INFILE) If Not StringInStr($TEXT, "REGEDIT4") Then ProgramExit("Error Opening .REG file|" & $REGFILE & " does not appear to be a valid Regedit4 formatted registry file.",1) EndIf EndFunc ;==>OpenFiles Func ParseFile() Dim $TEMP $TEXT =FileReadLine($INFILE) While $TEXT = "" $TEXT = FileReadLine($INFILE) Wend While 1 If StringLeft($TEXT,1) = "[" And StringRight($TEXT, 1) = "]" Then;Brackets at each end. found a key $KEY = StringMid($TEXT,2,StringLen($TEXT)-2); parse string for key name $TEXT = FileReadLine($INFILE);get next line EndIf While StringLeft($TEXT,1) <> "[" And StringRight($TEXT, 1) <> "]" And $TEXT <> "";read values until we see another key. While StringRight($TEXT,1) = "\";Join lines split by regedit export $TEXT = StringTrimRight($TEXT,1) $TEXT = $TEXT & FileReadLine($INFILE) Wend $TEMP = StringSplit($TEXT, "=");split line into value and valuedata $VALUE = TrimQuote($TEMP[1]);remove quotes If $VALUE = "@" Then ;change to autoit format for default value $VALUE = "" EndIf If StringInStr($TEMP[2],"hex:") Then $VALUETYPE = "REG_BINARY" $VALUEDATA = StringTrimLeft($TEMP[2],StringInStr($TEMP[2],"hex:")+3) ;Remove spaces and commas to properly format binary value $VALUEDATA = StringReplace($VALUEDATA," ","") $VALUEDATA = StringReplace($VALUEDATA,",","") ElseIf StringInStr($TEMP[2],"hex(2):") Then $VALUETYPE = "REG_EXPAND_SZ" $VALUEDATA = CharsToString(StringTrimLeft($TEMP[2],StringInStr($TEMP[2],"hex(2):")+6)) ElseIf StringInStr($TEMP[2],"hex(7):") Then $VALUETYPE = "REG_MULTI_SZ" $VALUEDATA = CharsToString(StringTrimLeft($TEMP[2],StringInStr($TEMP[2],"hex(7):")+6)) ElseIf StringInStr($TEMP[2],"dword:") Then $VALUETYPE = "REG_DWORD" $VALUEDATA = StringTrimLeft($TEMP[2],StringInStr($TEMP[2],"dword:")+5) Else $VALUETYPE = "REG_SZ" $VALUEDATA = TrimQuote($TEMP[2]) $VALUEDATA = StringReplace($VALUEDATA,'\"','"');reg file quotes are \" replace with quote $VALUEDATA = StringReplace($VALUEDATA,"\\","\");reg file backslashes are \\ replace with \ $VALUEDATA = StringReplace($VALUEDATA,"'","''");regstring in output file is enclosed with single quotes. this ensures single quotes in string are output EndIf ;inserted by rathore $VALUE = StringReplace($VALUE,'\"','"');reg file quotes are \" replace with quote $VALUE = StringReplace($VALUE,"\\","\");reg file backslashes are \\ replace with \ $VALUE = StringReplace($VALUE,"'","''");regstring in output file is enclosed with single quotes. this ensures single quotes in string are output ;inserted by rathore FileWriteLine($OUTFILE,'RegWrite(' & DblQuote($KEY) & "," & DblQuote($VALUE) & "," & DblQuote($VALUETYPE) & "," & SingleQuote($VALUEDATA) & ')') $TEXT = FileReadLine($INFILE) If @error <> 0 Then ExitLoop EndIf Wend $TEXT = FileReadLine($INFILE) If @error <> 0 Then ExitLoop EndIf Wend ProgramExit("Operation Complete|Input File: " & $REGFILE & @CR & "Output File: "& StringTrimRight($REGFILE,4) & ".au3",0) EndFunc ;==>ParseFile Func TrimQuote($INSTRING) ;remove leading and trailing quotes If StringLeft($INSTRING,1) = '"' Then $INSTRING= StringTrimLeft($INSTRING,1) EndIf If StringRight($INSTRING,1) = '"' Then $INSTRING = StringTrimRight($INSTRING, 1) EndIf Return $INSTRING EndFunc ;==>TrimQuote Func CharsToString($INSTRING) Dim $TEMPARRAY, $COUNT $INSTRING = StringReplace($INSTRING," ","") ;Remove trailing nulls While StringRight($INSTRING,3) = ",00" $INSTRING = StringTrimRight($INSTRING,3) Wend ;Create an array of character values and build string $TEMPARRAY = StringSplit($INSTRING, ",") $INSTRING = "" For $COUNT = 1 To $TEMPARRAY[0] If $TEMPARRAY[$COUNT] = "00" Then $INSTRING = $INSTRING & '" & @LF & "';separate items with linefeed character Else $INSTRING = $INSTRING & Chr(Dec($TEMPARRAY[$COUNT]));convert hex to dec then get character value and append to return string EndIf Next Return $INSTRING EndFunc ;==>CharsToString Func DblQuote($INSTRING) $INSTRING = Chr(34) & $INSTRING & Chr(34) Return $INSTRING EndFunc ;==>DblQuote Func SingleQuote($INSTRING) $INSTRING = Chr(39) & $INSTRING & Chr(39) Return $INSTRING EndFunc ;==>SingleQuote Func ProgramExit($INSTRING,$ERROR) Dim $FLAGS,$TEMPARRAY If $ERROR = 1 Then $FLAGS = 16 Else $FLAGS = 64 EndIf $TEMPARRAY = StringSplit($INSTRING, "|") MsgBox($FLAGS, $TEMPARRAY[1], $TEMPARRAY[2]) If $INFILE <> -1 Then FileClose($INFILE) EndIf If $OUTFILE <> -1 Then FileClose($OUTFILE) EndIf Exit EndFunc ;==>ProgramExit now the .reg file REGEDIT4 [HKEY_CURRENT_USER\Software\Helios\TextPad 4\Document Classes\C/C++] "Type"=dword:00000002 "Members"=hex(7):2a,2e,43,00,2a,2e,43,50,50,00,2a,2e,48,00,2a,2e,48,50,50,00,\ 2a,2e,43,58,58,00,2a,2e,48,58,58,00,2a,2e,49,4e,4c,00,2a,2e,52,43,00,2a,2e,\ 52,43,32,00,00 "Properties"=hex:50,00,00,00,13,03,00,00,01,00,00,00,01,00,00,00 "TabStops"=hex:00,00,00,00,00,00,00,00,04,00,04,00,00,00,00,00,00,00,00,00,00,\ 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,\ 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,\ 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,\ 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,\ 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00 "SyntaxProps"=hex:01,00,00,00 "SyntaxFile"="E:\\PROGRAM FILES\\TEXTPAD 4\\System\\CPP.SYN" "WordChars"="_" Link to comment Share on other sites More sharing options...
Guest rathore Posted April 10, 2004 Share Posted April 10, 2004 oops!...maybe Dan doesn't like bugs being found in his code. and i thought i was helping! i kind of liked this code coz as i've already stated, it has saved me a lot of coding that someday i was going to do. i just wanted it to be improved and applicable to all reg entries. Link to comment Share on other sites More sharing options...
Dan Posted April 10, 2004 Author Share Posted April 10, 2004 oops!...maybe Dan doesn't like bugs being found in his code. and i thought i was helping! i kind of liked this code coz as i've already stated, it has saved me a lot of coding that someday i was going to do. i just wanted it to be improved and applicable to all reg entries.It's not a problem. Report them all. I wrote it to help with a specific problem and didn't encounter any of the bugs you found as the .reg files I was working with were strings (without " or \ characters) and dwords. The next time i use this, it will be bug free and able to handle any possible .reg formatting thanks to your diligent testing.Your last post said you had a problem with extra entries being placed in the reg file, I can't duplicate this. Can you give me some more details? Link to comment Share on other sites More sharing options...
Guest rathore Posted April 10, 2004 Share Posted April 10, 2004 sure! follow these steps: make .au3 from the reg file i've given. export the key to another reg file. compare both reg files. Link to comment Share on other sites More sharing options...
Dan Posted April 10, 2004 Author Share Posted April 10, 2004 So it looks like reg_multi_sz were the only issue. Enclosing the string in quotes is not necessary for reg_sz_multi types. I added an else statement to handle it. Link to comment Share on other sites More sharing options...
Guest rathore Posted April 10, 2004 Share Posted April 10, 2004 thanx... will check it out! Link to comment Share on other sites More sharing options...
Guest rathore Posted April 10, 2004 Share Posted April 10, 2004 the members value in the au3 generated is coming out like this: RegWrite("HKEY_CURRENT_USER\Software\Helios\TextPad 4\Document Classes\C/C++","Members","REG_MULTI_SZ",*.C" & @LF & "*.CPP" & @LF & "*.H" & @LF & "*.HPP" & @LF & "*.CXX" & @LF & "*.HXX" & @LF & "*.INL" & @LF & "*.RC" & @LF & "*.RC2) should've come out like: RegWrite("HKEY_CURRENT_USER\Software\Helios\TextPad 4\Document Classes\C/C++","Members","REG_MULTI_SZ","*.C" & @LF & "*.CPP" & @LF & "*.H" & @LF & "*.HPP" & @LF & "*.CXX" & @LF & "*.HXX" & @LF & "*.INL" & @LF & "*.RC" & @LF & "*.RC2") the quotes at the beginning & end came out missing. i've fixed it ... the new line 76 should be: FileWriteLine($OUTFILE, 'RegWrite(' & DblQuote($KEY) & "," & DblQuote($VALUE) & "," & DblQuote($VALUETYPE) & "," & '"'&$VALUEDATA & '")') Link to comment Share on other sites More sharing options...
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