Jump to content

Copy registry keys (recursively)


JSunn
 Share

Recommended Posts

Hi,

I was working on this for something else and thought maybe it would come in handy for someone. You provide a source key (to search / copy from) and a destination key that does not yet exist to copy to and this script will search through and copy all keys / values and subkeys from the source to the destination. I used it for copying Outlook profiles.

Thanks,

-John

CODE
Copies all keys in the source key to the destination key.

;Author:JSunn

Dim $valArr[1]

;Source key to copy (along with all subkeys)

Global $SourceKey = "HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\Default Outlook Profile"

;Destination key to copy to.

Global $DestKey = "HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\NewUser"

RegSearch($SourceKey)

Func RegSearch($current)

$k = 1

While 1

$CurrKey = RegEnumKey($current, $k)

If @error = 0 then

WriteVal($current & "\" & $currKey)

$recKey = RegEnumKey($Current & "\" & $currkey, 1)

If @error = 0 then

regSearch($current & "\" & $currKey)

Else

Endif

Else

ExitLoop

Endif

$k = $k + 1

Wend

EndFunc

Func WriteVal($key)

$nKey = Stringreplace($key, $SourceKey, $DestKey)

$v = 1

While 1

$CurrVal = RegEnumVal($key, $v)

If @error = 0 then

$val = RegRead ($key, $CurrVal)

Switch @extended

Case 0

$type = "REG_NONE"

Case 1

$type = "REG_SZ"

Case 2

$type = "REG_EXPAND_SZ"

Case 3

$type = "REG_BINARY"

Case 4

$type = "REG_DWORD"

Case 5

$type = "REG_DWORD_BIG_ENDIAN"

Case 6

$type = "REG_LINK"

Case 7

$type = "REG_MULTI_SZ"

Case 8

$type = "REG_RESOURCE_LIST"

Case 9

$type = "REG_FULL_RESOURCE_DESCRIPTOR"

Case 10

$type = "REG_RESOURCE_REQUIREMENTS_LIST"

EndSwitch

;Write the new key and values

Regwrite($nKey, $CurrVal, $type, $val)

Else

ExitLoop

Endif

$v = $v + 1

Wend

Endfunc

Edited by JSunn
Link to comment
Share on other sites

  • Moderators

Case 8

$type = "REG_RESOOURCE_LIST"

^^ is that right?

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...