My requirement is to read a REG_DWORD from the registry and write it to another location. I have succeeded in reading from a registry location, but don't know how to write.
My code:
@echo off
REG QUERY HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\NetCache /v "OfflineDirRenameDelete"
SET previous=OfflineDirRenameDelete
REG ADD HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\MySoftware /v "CacheDelete" /t REG_DWORD /d previous /f
This code fails, as "reg add" doesn't understand the "previous" variable
I am able to hard-code a value and set it to the registry. For example, this works:
REG ADD HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\MySoftware /v "CacheDelete" /t REG_DWORD /d 5454 /f
But I basically don't know how to dynamic REG_DWORD value to the registry.
The problem was that the REG QUERY instruction was returning something the name of the registry key, the type of it, and the value together. For example, it would be something like:
And I was trying to set this value to another REG_DWORD in the registry, which obviously failed since this is more than a DWORD. And I may have had some syntax error and stuff in trying that too, so there's no wonder it failed.
The following code worked for me:
Hope this helps someone!
Use
%previous%
to get the content of the variable.Here is a quick reference on using variables in batch files.