Jump to content
Sign in to follow this  

Export Registry Keys Syntax Trouble

Recommended Posts


I am trying to export some registry keys before I overwrite them in case I need to restore them later. I seem to be having trouble with the syntax or maybe the placement of the quotes. I want to export them as a .reg file and place them in a folder called "Registry Backups" from whatever directory the script is executed from. Below is my feable attempt that is not working. It is just a test right now before I actually add it to a larger script I am working on. If this seems like the wrong way to go about this or whatever please advise me but bare in mind that I am still trying to learn so my level of knowledge is low and I likely can not implement anything overly complex. Thank you in advance for your time.


If Not FileExists(@ScriptDir & "\Registry Backup") Then DirCreate(@ScriptDir & "\Registry Backup") ;<===Create Directory

RunWait('"' & @ComSpec & '" /c REGEDIT /E @ScriptDir "\Registry Backup\test.reg HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run', '', @SW_Show)

Share this post

Link to post
Share on other sites


If Not FileExists(@ScriptDir & 'Registry Backup') Then
    DirCreate(@ScriptDir & 'Registry Backup')
    Sleep(1000); <-- needed on some flash drives, otherwise the script will get ahead of itself and RegEdit will error.

RunWait(@ComSpec & ' /c REGEDIT /E "' & @ScriptDir & 'Registry Backuptest.reg" "HKEY_CURRENT_USERSoftwareMicrosoftWindowsCurrentVersionRun"', '', @SW_Show)

Or, in a function. Example...


_RegKeyExport('HKEY_CURRENT_USERSoftwareMicrosoftWindowsCurrentVersionRun', 'CU_Run.reg')
_RegKeyExport('HKEY_CURRENT_USERSoftwareMicrosoftWindowsCurrentVersionRunOnce', 'CU_RunOnce.reg')
_RegKeyExport('HKEY_LOCAL_MACHINESoftwareMicrosoftWindowsCurrentVersionRun', 'LM_Run.reg')
_RegKeyExport('HKEY_LOCAL_MACHINESoftwareMicrosoftWindowsCurrentVersionRunOnce', 'LM_RunOnce.reg')

Func _RegKeyExport($sKey, $sRegFile)
    Local $sFolder = @ScriptDir & 'Registry Backup'
    If Not FileExists($sFolder) Then
        If Not DirCreate($sFolder) Then
            Return MsgBox(8240, 'RegKeyExport', 'Could Not Create Folder:' & @CRLF & $sFolder)
    Local $sFile = $sFolder & '' & $sRegFile
    RunWait('regedit.exe /e "' & $sFile & '" "' & $sKey & '"', @ScriptDir)
Edited by ripdad

"The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward

Share this post

Link to post
Share on other sites

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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...