Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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)

like image 200
DP99 Avatar asked Jun 27 '11 17:06

DP99


People also ask

How do you check if a registry key exists in a batch file?

How do I check if a key is present in the windows registry. This can be done using reg query key : This command will set %errorlevel% . errorlevel=0 means the key exists.

How do I read a value from the Windows Registry?

Use the GetValue method, specifying the path and name) to read a value from registry key. The following example reads the value Name from HKEY_CURRENT_USER\Software\MyApp and displays it in a message box.


2 Answers

simple as that:

reg add "HKCU\Control Panel\Desktop\WindowMetrics" /v MessageFont /t REG_BINARY /d f5ffffff0000000000000000000000009001000000000001000000005400610068006f006d00610000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 /f

  1. You can abbreviate HKEY_Current_User to HKCU.
  2. Put the registry key in quotes to avoid parsing errors due to the spaces in there.
  3. 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.

like image 112
Gerd Avatar answered Sep 24 '22 19:09

Gerd


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
like image 40
brett rogers Avatar answered Sep 21 '22 19:09

brett rogers