'How to parse a REG_BINARY value to a registry key using a batch file?
here is a (just) example:
reg add HKEY_CURRENT_USER\Control Panel\Desktop\WindowMetrics /v MessageFont /t REG_BINARY /d "hex:f5,ff,ff,ff,00,00,00,00,00,00,00,00,00,00,00,00,90,01,00,00,\ 00,00,00,01,00,00,00,00,54,00,61,00,68,00,6f,00,6d,00,61,00,00,00,00,00,00,\ 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,\ 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00" /f
it doesn't work.
Many thanks in advance.
(btw, which code tags should be used here?)
EDIT: Sorry for the delay (i haven't got a reply here for several days, so i was googling and trying to find solution by myself) and thank you for the reply.
I solved the issue by removing "hex" and commas. Binary values should be added as a long row of numeric characters w/o spaces and commas.
Now i have another problem. How can i change just the value of an entry using reg command? For instance i should change the value of 'Default' registry entry from something to 'value not set' or vice versa. If i use 'reg add' command for that, it adds another entry with the same name instead of changing the value of the existing one. I can't use 'delete the old one and add a new one' technique, because it's not possible to delete 'Default' entry.
I need to do that through a batch file not reg file. (but anyway it would be good to know how could it be accomplished by reg file as well)
Thanks a lot
EDIT2: the solution for deletion of a value of a Default entry: reg delete HKLM...\Key /ve /f
for modifying entry values regini should be used. http://support.microsoft.com/kb/264584 (explanation in this page is a bit vague and maybe even inaccurate) put in a batch file: regini c:\testregini.txt where testregini.txt contains: HKEY_LOCAL_MACHINE...\Key EntryXY = somevalue ( or "value not set", or whatever of that data type)
Solution 1:[1]
simple as that:
reg add "HKCU\Control Panel\Desktop\WindowMetrics" /v MessageFont /t REG_BINARY /d f5ffffff0000000000000000000000009001000000000001000000005400610068006f006d00610000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 /f
- You can abbreviate HKEY_Current_User to HKCU.
- Put the registry key in quotes to avoid parsing errors due to the spaces in there.
- For the data, you will have to remove the quotes, the "hex:" prefix, the commas and the line breaks (backslashes) so that only the numbers remain.
That's it! I' just wondering why this was of no interest to anyone here before.
Solution 2:[2]
I'm not sure how to do it in a regular batch file, but here's how you can do it using PowerShell, using an example of setting the failure actions for the ASP.NET State service:
Let's say that this is what an export of your value looks like:
[HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\aspnet_state]
"FailureActions"=hex:50,33,01,00,00,00,00,00,00,00,00,00,03,00,00,00,0e,00,00,\
00,01,00,00,00,00,00,00,00,01,00,00,00,00,00,00,00,01,00,00,00,00,00,00,00
You put the hex values into a byte array and then use that value to set the registry value:
$failureActionsValue = ([byte[]](80,51,01,00,00,00,00,00,00,00,00,00,03,00,00,00,14,00,00,00,01,00,00,00,00,00,00,00,01,00,00,00,00,00,00,00,01,00,00,00,00,00,00,00))
Set-ItemProperty -Path 'HKLM:\System\ControlSet001\services\aspnet_state' -Name "FailureActions"
-Value $failureActionsValue
Solution 3:[3]
This article helped me out but to get this to work in cmd I had to change the line to something like this:
REG ADD "HKEY_CURRENT_USER\Control Panel\Desktop" /v "UserPreferencesMask" /t REG_BINARY /d 9F3E078012000000 /f
The /f makes it so the user is not prompted to confirm the change.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | mivk |
| Solution 2 | brett rogers |
| Solution 3 | Ivan Vinogradov |
