Moderators big_daddy Posted November 2, 2006 Moderators Share Posted November 2, 2006 expandcollapse popup$sRegHive = "HKEY_LOCAL_MACHINE" $sRegKey = "SOFTWARE\AutoIt v3\AutoIt" $sRegKeyNew = "SOFTWARE\AutoIt v3\AutoIt New" _RegCopyKey($sRegHive, $sRegKey, $sRegKeyNew, False) If @error Then MsgBox(48, "Error", "There was an error while copying the key.") Else MsgBox(64, "Success", "The key was copied successfully.") EndIf ;=============================================================================== ; ; Function Name: _RegCopyKey ; Description:: Copies a registry key. ; Parameter(s): $s_RegHive - The registry hive of the key. ; $s_RegKey - The registry key to copy from. ; $s_RegKeyNew - The registry key to copy to. ; $f_Delete - Specifies whether to delete the original key. ; Requirement(s): AutoIt v3.2.0.1 ; Return Value(s): On Success - Returns 1 ; On Failure - Returns 0 and sets @ERROR = 1 ; Author(s): Bob Anthony (big_daddy) ; ;=============================================================================== ; Func _RegCopyKey($s_RegHive, $s_RegKey, $s_RegKeyNew, $f_Delete = False) Local $s_TempRegFile = @TempDir & "\~regfile.reg" FileDelete($s_TempRegFile) RunWait("regedit /e:a " & $s_TempRegFile & ' "' & $s_RegHive & "\" & $s_RegKey & '"') If Not FileExists($s_TempRegFile) Then SetError(1) Return 0 EndIf $s_File = FileRead($s_TempRegFile) If @error Then SetError(1) Return 0 EndIf $s_FileNew = StringReplace($s_File, $s_RegKey, $s_RegKeyNew) If @error Or @extended = 0 Or $s_FileNew = "" Then SetError(1) Return 0 EndIf $h_File = FileOpen($s_TempRegFile, 2) If $h_File = -1 Then SetError(1) Return 0 EndIf $f_Return = FileWrite($h_File, $s_FileNew) If Not $f_Return Then SetError(1) Return 0 EndIf FileClose($h_File) If $f_Delete Then RegDelete($s_RegKey) EndIf RunWait("regedit.exe /s " & $s_TempRegFile) FileDelete($s_TempRegFile) SetError(0) Return 1 EndFunc ;==>_RegCopyKey Link to comment Share on other sites More sharing options...
jvanegmond Posted November 2, 2006 Share Posted November 2, 2006 First of all, I want to thank you for adding those comments, it has helped my a great deal in understanding your code. Just kidding. Your approach to copying a registry key has made me do the same for my environment at school, allowing me to copy certain registry values to HKEY_LOCAL_USERS key, and on boot copy them to HKEY_LOCAL_MACHINE. This allows me to use AutoIt on any PC at school. github.com/jvanegmond Link to comment Share on other sites More sharing options...
Moderators big_daddy Posted November 2, 2006 Author Moderators Share Posted November 2, 2006 Sorry for the lack of comments, I throw this together in about 30-45 minutes last night before in went to bed. I plan on rewriting the function to allow copying either a key or a value. I will also get rid of the $sRegHive variable as there is no need for it. Anyhow glad you found it useful. Link to comment Share on other sites More sharing options...
mlazovjp Posted April 15, 2010 Share Posted April 15, 2010 Sorry for the lack of comments, I throw this together in about 30-45 minutes last night before in went to bed. I plan on rewriting the function to allow copying either a key or a value. I will also get rid of the $sRegHive variable as there is no need for it. Anyhow glad you found it useful. There is a much easier way to do it using Windows reg.exe file. http://commandwindows.com/reg.htm C:\Windows\system32>reg copy /? REG COPY KeyName1 KeyName2 [/s] [/f] KeyName [\\Machine\]FullKey Machine Name of remote machine - omitting defaults to the current machine. Only HKLM and HKU are available on remote machines. FullKey ROOTKEY\SubKey ROOTKEY [ HKLM | HKCU | HKCR | HKU | HKCC ] SubKey The full name of a registry key under the selected ROOTKEY. /s Copies all subkeys and values. /f Forces the copy without prompt. Examples: REG COPY HKLM\Software\MyCo\MyApp HKLM\Software\MyCo\SaveMyApp /s Copies all subkeys and values under the key MyApp to the key SaveMyApp REG COPY \\ZODIAC\HKLM\Software\MyCo HKLM\Software\MyCo1 Copies all values under the key MyCo on ZODIAC to the key MyCo1 on the current machine Link to comment Share on other sites More sharing options...
dantay9 Posted April 16, 2010 Share Posted April 16, 2010 Please refrain from reviving 3 year old threads. Link to comment Share on other sites More sharing options...
wraithdu Posted April 16, 2010 Share Posted April 16, 2010 I prefer mine anyway. 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