Jump to content

RegWrite DWORD and BINARY


Recommended Posts

Not sure how to go about this, and well I can't seem to find anything about how to do it either.

I have a REG_BINARY key which is in hexadecimal. When exported from regedit, it looks like this:

"License"=hex:xx,xx,xx,xx,xx,xx,xx,xx,xx,xx,xx,xx,xx,xx,xx,xx

Now in AutoIt I've tried doing:

RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Raxco\PerfectDisk\10.0", "License", "REG_BINARY", "xx,xx,xx,xx,xx,xx,xx,xx,xx,xx,xx,xx,xx,xx,xx,xx")

I've tried spaces (instead of commas) and removing the commas as well.

Also have some DWORD keys as well, and exported from regedit they look like so:

"Wizard"=dword:0000000f

And the AutoIt code I've tried:

RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Raxco\PerfectDisk\10.0", "Wizard", "REG_DWORD", "00 00 00 0f")

Also tried without spaces too.

Hopefully somebody on here has successfully used these functions before and can help me :P

Link to comment
Share on other sites

#include <String.au3>
$sHexTextStr="0b1a2c"
$bBinary=StringToBinary(_HexToString($sHexTextStr))
consolewrite($bBinary&@CRLF)

Link to comment
Share on other sites

You can do that with

$binary = Binary("0x0123456789ABCDEF")
RegWrite("HKCU\Software\__Bintest", "BinaryVal", "REG_BINARY", $binary)
$read = RegRead("HKCU\Software\__Bintest", "BinaryVal")
MsgBox(0, 'Binary Write / Read', "Written:  " & $binary & @CRLF & "Read:    " & $read)

RegDelete("HKCU\Software\__Bintest")
Edited by ProgAndy

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Link to comment
Share on other sites

Dang, you know I hadn't even thought of Binary. So in this case, when jdrom is faced with a RegEdit style binary string, he'll just need to prefix '0x' to the string, like such..

$sHexTextStr="0b1a2c"
$bBinary=Binary('0x'&$sHexTextStr)
ConsoleWrite($bBinary&@CRLF)

Thx Progandy - I actually have a RegEdit parser of my own and was wondering if there was a better way!

Link to comment
Share on other sites

Sadly I don't even know enough about AutoIt to understand that code you guys posted...

I'm guessing your converting hex into binary? And 0x needs to be added in front of the hex value? I'd like to understand it though since obviously converting hex into ASCII and using that is far from ideal.

Would this be how I'd implement it?

RegWrite("HKEY_LOCAL_MACHINESOFTWARERaxcoPerfectDisk10.0", "License", "REG_BINARY", Binary ('0x'&'123ABC'))
Edited by jdrom
Link to comment
Share on other sites

You were exporting from RegEdit, so I had assumed you had gathered a string of hexadecimal values (and hopefully removed the commas) This would result in a string like I posted, for example "a0b1c3d40eff1b2c'. That, in string form, would need 0x added to the front.

What you describe, "123ABC" depends on what it is you are doing. As a HEX string, that will give you 0x123ABC, but do you want the binary string to represent the actual characters '123abc'', or are those the hexadecimal values. If its the latter, you can put it in as '0x123ABC'. If the former, then you'll need to use StringToBinary I believe

Link to comment
Share on other sites

Yup, but it's useless to concatenate these strings because "0x123ABC" and what you've wrote is the same. Try to test this things using the ConsoleWrite to see what the final result is because this -> "0x123ABC" is not interpreted as hex: 01,02,03,0A,0B,0C...

Example:

Dim $Var = Binary('0x123ABC')
Dim $tBuff = DllStructCreate('byte[' & BinaryLen($Var) & ']')

DllStructSetData($tBuff, 1, $Var)
ConsoleWrite(DllStructGetData($tBuff, 1) & @LF & @LF)

For $i = 1 To BinaryLen($Var)
    ConsoleWrite(Hex(DllStructGetData($tBuff, 1, $i), 2) & @LF)
Next
$tBuff = 0
Link to comment
Share on other sites

Yup, but it's useless to concatenate these strings because "0x123ABC" and what you've wrote is the same. ..

Authenticity, I tested it with RegWrite(), and the way I had it works perfectly. I don't know where you're coming from.

By the way, you're example doesn't write anything to the console and ends up in an endless loop. (AutoIT v3.3) *edit* retried, and worked the second time (don't know why it failed the first time. In any case, the results are the same as what was expected - these are hex *pairs*, as would be retrieved in grabbing text from a RegEdit file)*

Here's code that shows writing to the registry:

$sHexTextStr="0b1a2c"
RegWrite("HKEY_CURRENT_USER\Software\1Key","testbin","REG_BINARY",Binary('0x'&$sHexTextStr))

I export that key using RegEdit, and what is the result?

Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\1key]
"testbin"=hex:0b,1a,2c

Works just as it should.

-Ascend4nt

Edited by ascendant
Link to comment
Share on other sites

$sHexTextStr="0b1a2c"
RegWrite("HKEY_CURRENT_USER\Software\1Key","testbin","REG_BINARY",Binary('0x'&$sHexTextStr))
Thanks guy (or girls) :P

I used Ascendants way though, easier for me to understand and works perfectly. Though I ditched the variable and just put my hex string in directly (without commas of course). It's the 2nd line in my script anyways so I don't see the need for a variable.

Link to comment
Share on other sites

  • 13 years later...

Nothing like dredging up the very, very dead threads, BUT I got here by searching the forum.  After some testing I'll clarify how this works:

My reg export from another machine looked like this:
[HKEY_CURRENT_USER\SOFTWARE\Microsoft\Internet Explorer\BrowserEmulation\ClearableListData]
"UserFilter"=hex:41,1f,00,00,53,08,ad,ba,01,00,00,00,28,00,00,00,01,00,00,00,\
  01,00,00,00,0c,00,00,00,18,53,13,52,69,1c,d8,01,01,00,00,00,05,00,6c,00,6f,\
  00,63,00,61,00,6c,00

To make that work with RegWrite, I removed all commas, spaces, and line breaks(\) from the exported value, prefixed the "0x" and made this:

RegWrite("HKEY_CURRENT_USER\SOFTWARE\Microsoft\Internet Explorer\BrowserEmulation\ClearableListData", "UserFilter", "REG_BINARY", "0x411f00005308adba010000002800000001000000010000000c00000018531352691cd8010100000005006c006f00630061006c00")

and it worked perfectly.  After the RegWrite executed, I exported the key from RegEdit and it came out the exact same as the previous export. 

(I needed this to deploy this value to all users using my CMS.  FWIW, this is the value that puts "HTTPS://local/" in IE compatibility mode.)

Hope this helps someone someday.

Link to comment
Share on other sites

  • Developers
6 minutes ago, TheyCallMeBacon said:

Nothing like dredging up the very, very dead threads, BUT I got here by searching the forum. 

Seriously...  You register and the first thing you feel like doing is posting in an 13 years ago burries thread.

You..  just sit in a corner until that feeling goed away the next time and refrain from posting!   Thanks

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • Jos locked this topic
Guest
This topic is now closed to further replies.
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...