LxP Posted July 9, 2005 Posted July 9, 2005 (edited) Hi guys,Behold my first UDF, _regClone(). I wrote this because I want to back up registry entries over a reboot on a foreign computer and can't be sure of which parts of the file system have write access, survive a reboot due to configuration of disk cleaners etc. (and obviously if I can write to a certain section of the registry then none of this will be an issue).Thanks to Kurt (/dev/null) for making this possible by extending the RegRead() function!Please do let me know if you use/like it or if you have suggestions for improvement._regClone.au3CODE;; _regClone(); Clones an entire registry key to another location.;; Requirements:; AutoIt v3.1.1.56 or later;; Syntax:; _regClone($srcKey, $tgtKey);; Parameters:; * $srcKey: location of key to clone.; * $tgtKey: location of cloned key.;; Examples:; * _regClone("HKLM\Software\AutoIt v3", "HKLM\Software\AutoIt v3 Backup"); * _regClone("HKCU\Software\Adobe", "HKCU\Software\AdobeBackup");; @error return values:; * 0: success; * 1: could not write to target sub/key; * 2: could not read from source sub/key;; Author:; Alex Peters, 9/7/2005;; Notes:; * The _regClone() function calls itself recursively to clone subkeys. If; renaming the function then be sure to update the function's code to; reflect this name change.; ____________________________________________________________________________func _regClone($srcKey, $tgtKey) ; Create target key (necessary if source key is empty). if (regWrite($tgtKey) = 0) then setError(1) return endIf ; Enumerate source key's values and write them to the target key. local $valIdx = 1 while (1) local $valName = regEnumVal($srcKey, $valIdx) ; There are no more values if @error = -1. if (@error = -1) then exitLoop ; The source key could not be read if @error = 1. if (@error = 1) then setError(2) return endIf local $valData = regRead($srcKey, $valName) local $valType select case @extended = 1 $valType = "REG_SZ" case @extended = 2 $valType = "REG_EXPAND_SZ" case @extended = 3 $valType = "REG_BINARY" case @extended = 4 $valType = "REG_DWORD" case @extended = 7 $valType = "REG_MULTI_SZ" endSelect if (regWrite($tgtKey, $valName, $valType, $valData) = 0) then setError(1) return endIf $valIdx = $valIdx + 1 wEnd ; Enumerate source key's subkeys and write them to the target key. local $subkeyIdx = 1 while (1) local $subkey = "\" & regEnumKey($srcKey, $subkeyIdx) ; @error = -1 if there are no more subkeys. if (@error = -1) then exitLoop ; @error = 1 if the key could not be read. if (@error = 1) then setError(2) return endIf _regClone($srcKey & $subkey, $tgtKey & $subkey) ; Propagate any error back to the caller. if (@error) then setError(@error) return endIf $subkeyIdx = $subkeyIdx + 1 wEndendFunc10/7/2005: Function now copies empty keys as expected (thanks Lazycat).21/10/2005: Added as a file download (see above). Edited October 21, 2005 by LxP
Lazycat Posted July 9, 2005 Posted July 9, 2005 Good function, this can be usefull in some situations. Works just fine, except fact, that not copy empty keys... Koda homepage ([s]Outdated Koda homepage[/s]) (Bug Tracker)My Autoit script page ([s]Outdated mirror[/s])
LxP Posted July 9, 2005 Author Posted July 9, 2005 Good function, this can be usefull in some situations. Works just fine, except fact, that not copy empty keys...Thanks for pointing that out, Lazycat!I originally had code to explicitly create the key, but after testing I removed it because RegWrite() would create it to hold the subkeys and/or values. I didn't give any thought to empty keys. I suppose I should have re-tested!
busysignal Posted July 12, 2005 Posted July 12, 2005 LxP, nice work. This definitely a useful function. What's next?
LxP Posted July 12, 2005 Author Posted July 12, 2005 LxP, nice work. This definitely a useful function. What's next?Thanks busysignal! I'm looking at writing some more registry-related functions along the lines of _regFind() and _regReplace(). It will be possible to limit the search to a specific key, to work with key names, item names and/or item values and to search for a whole value or part thereof.I'm hoping that no one else beats me to it because I sure would like to make some contributions to the AutoIt package of my own!
busysignal Posted July 12, 2005 Posted July 12, 2005 Thanks busysignal! I'm looking at writing some more registry-related functions along the lines of _regFind() and _regReplace(). It will be possible to limit the search to a specific key, to work with key names, item names and/or item values and to search for a whole value or part thereof.I'm hoping that no one else beats me to it because I sure would like to make some contributions to the AutoIt package of my own! <{POST_SNAPBACK}>Yes, you could write a whole suite of _regTools. If you do a search for registry udfs you will find that there are some but not what you are doing. Also, you should make a option in any replace or remove functions that have the ability to write the regkey/data to a file as a backup. I don't know of too many registry tools that actually have a UNDO history capability. Cheers..
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