Page 1 of 1 1
Topic Options
#176180 - 2007-05-10 05:14 PM Copy registry key
skumflum Offline
Lurker

Registered: 2007-05-10
Posts: 2
Hi’

I’m about to create an addition to a login script. I need to copy an entire registry key tree from HKEY_LOCAL_MACHINE to HKEY_CURRENT_USER.

To be more specific :
• HKEY_LOCAL_MACHINE\Software\Microsoft\Active Setup\Installed Components\{89820200-ECBD-11cf-8B85-00AA005B4383}\Version

TO

• HKEY_CURRENT_USER\Software\Microsoft\Active Setup\Installed Components\{89820200-ECBD-11cf-8B85-00AA005B4383}\Locale

I’m a KIX newbie. Can somebody point me in the right direction?

Regards
Søren

Top
#176181 - 2007-05-10 05:33 PM Re: Copy registry key [Re: skumflum]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
You could use readvalue to read the values in the source reg key and use writevalue to write the stuff to the destination reg key. Writevalue does not care if the path exists or not. It will create the path if it does not exist.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#176182 - 2007-05-10 05:33 PM Re: Copy registry key [Re: Mart]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
BTW: forgot something Welcome to the board \:D
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#176192 - 2007-05-11 12:50 AM Re: Copy registry key [Re: Mart]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4402
Loc: New Jersey
Actually, read/writevalue commands are only part of the story. If you want to copy an entire subtree, you will need to play with the EnumKey and EnumValue commands as well.

EnumKey is placed in a loop (as per the example in the manual) to "discover" each subkey path. For each value returned by EnumKey, you'll need to run an inner loop using EnumValue functions - this will return the name of each value in the key. Then you'll need to use ReadValue to read the data, and ReadType to determine the registry value type - you'll need this information for WriteValue. Now that you have the key, value, data, and type, you can translate the Key path from HKLM to HKCU as you need, and then use WriteValue with the key, value, data, and type arguments. The inner loop continues until an error occurs when there are no more values, and the outer loop searches for the next subkey. This process repeats until all subkeys and values are found and copied. Of course, you need to consider recursion - processing the subkeys within subkeys.

As you can see, this is not a trivial process. There are several UDFs that search the registry, such as this one from Howard, which also references on by Jens.

Hope this helps..

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#176197 - 2007-05-11 09:07 AM Re: Copy registry key [Re: Glenn Barnas]
Arend_ Moderator Offline
MM club member
*****

Registered: 2005-01-17
Posts: 1896
Loc: Hilversum, The Netherlands
Wouln't expert/import of the section be easier ?
Top
#176202 - 2007-05-11 09:53 AM Re: Copy registry key [Re: Arend_]
skumflum Offline
Lurker

Registered: 2007-05-10
Posts: 2
I was worried that the ”tree” stuff was difficult.

I’ll try to look at one from Howard :-)

Thanks

Top
#176210 - 2007-05-11 02:56 PM Re: Copy registry key [Re: Arend_]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4402
Loc: New Jersey
I considered using the load/unload hive commands, but the issue is to copy the structure of HKLM to HKCU for some reason - simple export/import won't work.

You might also consider using the REG command to export the HKLM, then read in each line, modifying it as needed, and either using WriteValue to write to the registry, or simply writing the modified lines back to a file and importing that file.

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#176213 - 2007-05-11 03:23 PM Re: Copy registry key [Re: Glenn Barnas]
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
It all depends on how much "tree" there is to begin with. There was a round of golf a while back that was all about the registry. One could glean a lot from it.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#176216 - 2007-05-11 05:44 PM Re: Copy registry key [Re: Glenn Barnas]
Arend_ Moderator Offline
MM club member
*****

Registered: 2005-01-17
Posts: 1896
Loc: Hilversum, The Netherlands
 Originally Posted By: Glenn Barnas
I considered using the load/unload hive commands, but the issue is to copy the structure of HKLM to HKCU for some reason - simple export/import won't work.

You might also consider using the REG command to export the HKLM, then read in each line, modifying it as needed, and either using WriteValue to write to the registry, or simply writing the modified lines back to a file and importing that file.

Glenn

Thats what I ment, REG export to file, modify where needed and import. \:\)

Top
#176235 - 2007-05-13 10:47 AM Re: Copy registry key [Re: skumflum]
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11634
Loc: Space
Are you sure you're wanting the entire tree ? Locale and Version are within that Key

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Active Setup\Installed Components\{89820200-ECBD-11cf-8B85-00AA005B4340}

HKEY_CURRENT_USER\SOFTWARE\Microsoft\Active Setup\Installed Components\{89820200-ECBD-11cf-8B85-00AA005B4340}

Is more so what you want isn't it? And why?

You could do something like this, I'll leave the editing to you or one of the other guys here to assist you.


You could shell out and run this
REG EXPORT "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Active Setup\Installed Components\{89820200-ECBD-11cf-8B85-00AA005B4340}" C:\WDU.REG

Then you would need to open and read the C:\WDU.REG file and replace the "HKEY_LOCAL_MACHINE" with "HKEY_CURRENT_USER"
You could then shell out and run REGEDIT /S C:\WDU.REG to place it into the HKEY_CURRENT_USER section.



Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 2220 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.068 seconds in which 0.032 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org