Nunos Posted December 2, 2012 Posted December 2, 2012 Hello- 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. #RequireAdmin 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)
ripdad Posted December 2, 2012 Posted December 2, 2012 (edited) #RequireAdmin 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. EndIf RunWait(@ComSpec & ' /c REGEDIT /E "' & @ScriptDir & 'Registry Backuptest.reg" "HKEY_CURRENT_USERSoftwareMicrosoftWindowsCurrentVersionRun"', '', @SW_Show) Or, in a function. Example... #RequireAdmin _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) EndIf Sleep(1000) EndIf ; Local $sFile = $sFolder & '' & $sRegFile RunWait('regedit.exe /e "' & $sFile & '" "' & $sKey & '"', @ScriptDir) EndFunc Edited December 3, 2012 by ripdad "The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward
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