Jump to content

Recommended Posts

Posted

I forgot that Regedit /e doesn't back up the complete registry but this code does.

Local $aHives[5] = ["HKCR", "HKCU", "HKLM", "HKU", "HKCC"]
Local $s_File = @YEAR & @MON & @MDAY & ".reg", $s_Rtn = "", $s_Proc_Err = ""
Local $s_Err_Msg = "The registry was successfully exported.", $s_Err = "", $h_Process, $s_Cmd
Local $s_DestFile = @DesktopDir & "\" & $s_File ;; Modify the path to what you want
FileDelete($s_DestFile)
SplashTextOn("Registry Backup", "Please wait while the registry is exported." & @CRLF & @CRLF & "This may take some time to complete.", 350, 100)
For $i = 0 To UBound($aHives) - 1
    $s_Cmd = @ComSpec & " /c reg export " & $aHives[$i] & " " & $s_File & " /y"
    $h_Process = Run($s_Cmd, @TempDir, @SW_HIDE, 0x8)
    While ProcessExists($h_Process)
  $s_Proc_Err = StderrRead($h_Process)
        If $s_Proc_Err Then
            $s_Err &= "Error exporting " & $aHives[$i] & @CRLF & @TAB & "Error: " & $s_Proc_Err & @CRLF
            ContinueLoop 2
        EndIf
    WEnd
    If NOT $i Then
        $s_Rtn &= FileRead(@TempDir & "\" & $s_File)
    Else
        $s_Rtn &= StringRegExpReplace(FileRead(@TempDir & "\" & $s_File), "(?is)(?m:^)Windows Registry.+?\v+\s+(\S.+)$", "$1"); We don't want the first 2 lines
    EndIf
Sleep(100);; Ease up on the processor
Next
SplashOff()
FileWrite($s_DestFile, $s_Rtn)
FileDelete(@TempDir & "\" & $s_File)
If $s_Err <> "" Then $s_Err_Msg = StringStripWS($s_Err, 2)
MsgBox(0, "Result", $s_Err_Msg)

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Posted (edited)

I forgot that Regedit /e doesn't back up the complete registry but this code does.

Local $aHives[5] = ["HKCR", "HKCU", "HKLM", "HKU", "HKCC"]
Local $s_File = @YEAR & @MON & @MDAY & ".reg", $s_Rtn = "", $s_Proc_Err = ""
Local $s_Err_Msg = "The registry was successfully exported.", $s_Err = "", $h_Process, $s_Cmd
Local $s_DestFile = @DesktopDir & "\" & $s_File ;; Modify the path to what you want
FileDelete($s_DestFile)
SplashTextOn("Registry Backup", "Please wait while the registry is exported." & @CRLF & @CRLF & "This may take some time to complete.", 350, 100)
For $i = 0 To UBound($aHives) - 1
    $s_Cmd = @ComSpec & " /c reg export " & $aHives[$i] & " " & $s_File & " /y"
    $h_Process = Run($s_Cmd, @TempDir, @SW_HIDE, 0x8)
    While ProcessExists($h_Process)
  $s_Proc_Err = StderrRead($h_Process)
        If $s_Proc_Err Then
            $s_Err &= "Error exporting " & $aHives[$i] & @CRLF & @TAB & "Error: " & $s_Proc_Err & @CRLF
            ContinueLoop 2
        EndIf
    WEnd
    If NOT $i Then
        $s_Rtn &= FileRead(@TempDir & "\" & $s_File)
    Else
        $s_Rtn &= StringRegExpReplace(FileRead(@TempDir & "\" & $s_File), "(?is)(?m:^)Windows Registry.+?\v+\s+(\S.+)$", "$1"); We don't want the first 2 lines
    EndIf
Sleep(100);; Ease up on the processor
Next
SplashOff()
FileWrite($s_DestFile, $s_Rtn)
FileDelete(@TempDir & "\" & $s_File)
If $s_Err <> "" Then $s_Err_Msg = StringStripWS($s_Err, 2)
MsgBox(0, "Result", $s_Err_Msg)

your code is not work for me.

but if i remove the /y parameter from command and i change it to:

$s_Cmd = @ComSpec & " /c reg export " & $aHives[$i] & " " & $s_File

it is work.

Edited by shai
Posted (edited)

The y just means to overwrite the files and if you look closely you will see that it's required to do that or delete the file between runs but after it's read. Another option would be to create separate files for each hive Then turn them all into one.

EDIT: I should add that it worked just fine for me in both Vista and 7

Edited by GEOSoft

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Posted

Here is a replacement that solved a system resource issue that I ran into after a few runs in Vista

Local $aHives[5] = ["HKCR", "HKCU", "HKLM", "HKU", "HKCC"]
Local $s_File = @YEAR & @MON & @MDAY & ".reg", $s_Rtn = "", $s_Proc_Err = ""
Local $s_Err_Msg = "The registry was successfully exported.", $s_Err = "", $h_Process, $s_Cmd
Local $s_DestFile = @DesktopDir & "\" & $s_File ;; Modify the path to what you want
FileDelete($s_DestFile)
SplashTextOn("Registry Backup", "Please wait while the registry is exported." & @CRLF & @CRLF & "This may take some time to complete.", 350, 100, 10, 10)
For $i = 0 To UBound($aHives) - 1
$s_HoldFile = $aHives[$i] & $s_File
FileDelete(@TempDir & "\" & $s_HoldFile)
    $s_Cmd = @ComSpec & " /c reg export " & $aHives[$i] & " " & $s_HoldFile ;& " /y"
    $h_Process = RunWait($s_Cmd, @TempDir, @SW_HIDE)
;; FileWrite code removed to save on system resources
Sleep(500);; Ease up on the processor
Next
For $i = 0 To UBound($aHives) -1
$s_HoldFile = @TempDir & "\" & $aHives[$i] & $s_File
$s_Rtn = FileRead($s_HoldFile)
If NOT $i Then
  FileWrite($s_DestFile, $s_Rtn)
Else
  $s_Rtn = StringRegExpReplace($s_Rtn, "(?is)(?m:^)Windows Registry.+?\v+\s+(\S.+)$", "$1")
EndIf
FileWrite($s_DestFile, $s_Rtn)
If FileFlush($s_DestFile) Then FileDelete($s_HoldFile)
Next
SplashOff()
If $s_Err <> "" Then $s_Err_Msg = StringStripWS($s_Err, 2)
MsgBox(0, "Result", $s_Err_Msg)

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

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
×
×
  • Create New...