Writing binary values to Windows registry

Using (or providing) components based on the "Win32" framework

Writing binary values to Windows registry

Postby OSRK on Sun Sep 08, 2024 5:59 pm

I'm trying to do write a binary value to Windows registry this way:

      ⎕USING,←⊂''
hkcu←Microsoft.Win32.Registry.CurrentUser
key←hkcu.CreateSubKey'Software\Foo\Bar'
key.SetValue'Data'(1 2 3 4)Microsoft.Win32.RegistryValueKind.Binary


but I get this:

      EXCEPTION: The type of the value object did not match the specified RegistryValueKind or the object could not be properly converted.
key.SetValue'Data'(1 2 3 4)Microsoft.Win32.RegistryValueKind.Binary


As far as I understand, the array I am passing is not considered as a byte array. And, as far as I understand, there is an issue with creating byte arrays: viewtopic.php?f=18&t=172
Are there any other hints on how to write binary Windows registry values, maybe?
User avatar
OSRK
 
Posts: 17
Joined: Tue Dec 27, 2016 8:48 am

Re: Writing binary values to Windows registry

Postby RichardP|Dyalog on Mon Sep 09, 2024 9:29 am

Following on from the post that you linked, I was able to write to a binary registry entry as follows:

Code: Select all
      ⎕using←''   ⍝ Using full paths to show where everything comes from
      hkcu←Microsoft.Win32.Registry.CurrentUser
      key←hkcu.CreateSubKey⊂'Software\Foo\'
      ba←System.Array.CreateInstance(System.Byte)4   ⍝ Create length 4 byte[] array
      ⎕io←0                                          ⍝ Match .NET index origin
      ba[2]←1                                        ⍝ Modify byte[] value
      ba[⍳4]
0 0 1 0
      key.SetValue'Data'(ba)Microsoft.Win32.RegistryValueKind.Binary


I then opened the registry editor and could see my new value in Computer\HKEY_CURRENT_USER\Software\Foo\Data
RichardP|Dyalog
 
Posts: 35
Joined: Fri Oct 12, 2018 3:05 pm


Return to Windows: GUI, COM/OLE/ActiveX

Who is online

Users browsing this forum: No registered users and 1 guest