How can I convert the REG_BINARY value from the registry to a string? (Vb.net)

I have a registry value that is stored as a binary value (REG_BINARY) containing file path information. The value is read into a byte array. But how can I convert it to a readable string?

I read about system.text.encoding.ASCII.GetString (value) but it doesn't work. As far as I know, the registry value is arbitrary binary data, not ASCII, which is the reason the method generates useless data.

Does anyone know how I can convert the data?

Example: (Part of a recording)

01 00 00 00 94 00 00 00 14 00 00 00 63 00 3A 00 5C 00 
70 00 72 00 6F 00 67 00 72 00 61 00 6D 00 6d 00 65 00 
5C 00 67 00 65 00 6D 00 65 00 69 00 6E 00 73 00 61 00 
6D 00 65 00 20 00 64 00 61 00 74 00 65 00 69 00 65 00 
6E 00 5C

      

Because of regedit, it should be:

............c.:.\.p.r.o.g.r.a.m.m.e.\.g.e.m.e.i.n.s.a.m.e. .d.a.t.e.i.e.n.\

      

The entry itself was created from Outlook. This entry is for an item with an added trip (fault tolerance)

+1


source to share


3 answers


Well, this is not arbitrary binary data - it is text data in some form of encoding. You need to find out what encoding is.

I wouldn't be surprised if it Encoding.Unicode.GetString(value)

worked, but if it doesn't, please post a sample (in hex) and I'll see what I can do. What does the documentation say about what data is put there?



EDIT: It looks like Encoding.Unicode is your friend, but starting at byte 12. Use

Encoding.Unicode.GetString(bytes, 12, bytes.Length-12)

      

+3


source


I also had this problem and I solved this way:

I have declared the variable as:

Dim encoding As System.Text.Encoding = System.Text.Encoding.Unicode

      



Then I do this in a loop:

    For Each Val As String In ValueName
        data = k.GetValue(Val)
        ListRecent.Items.Add(Val & ": " & encoding.GetString(data))
    Next

      

So, in a list called "ListRecent" I got a complete list of recent

+1


source


Using

Function Microsoft.Win32.RegistryKey.GetValue(name as String) as Object

      

Also see System.Text.Encoding

andSystem.Text.Encoding.Unicode

0


source







All Articles