Computer Hope

Microsoft => Microsoft DOS => Topic started by: anand_sridhar on November 08, 2008, 03:05:24 PM

Title: Copy Registry value from one key to another
Post by: anand_sridhar on November 08, 2008, 03:05:24 PM
Hello,
I am facing a simple problem to which I am unable to find a simple answer although I have a strong hunch the solution is simple.  ???

I have a value defined in the registry key

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\MyService\Parameters]
The value is a variable VAR_1 = -Xmx332m (REG_SZ)

What I wanted to do is read this variable value into this registry key

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment]

The whole problem occurs because I have to do this trick from a windows batch file.

Here are the few aprroaches I have in front of me -

1. Export the registry key , do a file string replace and import it back.  The con the exported .reg file is not in the same encoding format as a txt file, so I cant search and replace easily. Also, the file search and replace is unnecessarily complex in Windows.

2. Echo the registry value in command prompt and have it in a temp variable and then use that to add a new variable in the registry.  Again, this is difficult as when I echo the registry value, windows doesnt give me only the value but also other strings that make it difficult to parse through it.


Does any one have encountered a similar task before. ? I badly need to find out if there is a simple solution for this.

Thanks for the help.
Anand
Title: Re: Copy Registry value from one key to another
Post by: ALAN_BR on November 08, 2008, 04:25:53 PM
RegEdit will export in Unicode by default
You can also select Win9x/NT4 export, which I believe is simple ASCII.

I have no experience of REG.EXE, but this may be more suitable for control via a batch script

Regards
Alan
Title: Re: Copy Registry value from one key to another
Post by: anand_sridhar on November 08, 2008, 10:47:41 PM
Got the solution.
Here is how you go about -

1. Export reg file to a .reg file.
2. Use Type Command to convert the .reg file into an ASCII File.
3. Replace using any file replacement utility.
4. rename the file to reg file.
5. Import the reg file.

This works absolutely fine with a small glitch though.  I can very well observe in the registry editor that the Values are being created. However , when I try to echo these values on the command prompt, these values do not show up.
the way around is to open Environment Variables manager through My Computer and save from there.
BTW, the registry variables I tried to create above were new environment variables.

Do you know any way to save the imported reg file thus created or to have windows pick up the environment variables created thus from command prompt.?