Jump to content
Sign in to follow this  
JSunn

Copy registry keys (recursively)

Recommended Posts

JSunn

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

Share this post


Link to post
Share on other sites
SmOke_N

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.

Share this post


Link to post
Share on other sites
JSunn

Good catch Smoke... Guess I was wondering to myself what a REG_RESOURCE_LIST was anyway. It was taken from the constants.au3 file, although I've never heard of such a thing.

-John

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.