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

萝らか妹 提交于 2020-01-02 10:02:45

问题


I have a registry value which is stored as a binary value (REG_BINARY) holding information about a filepath. The value is read out into an byte array. But how can I transform it into a readable string?

I have read about system.text.encoding.ASCII.GetString(value) but this does not work. As far as I got to know the registry value is arbitrary binary data and not ASCII which is the reason for the method to produce useless data.

Does anybody know how I can convert the data?

Sample: (A piece of the entry)

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

Due to the regedit this is supposed to 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. It's an entry for an disabled addin item (resiliency)


回答1:


Well, it's not arbitrary binary data - it's text data in some kind of encoding. You need to find out what the encoding is.

I wouldn't be surprised if Encoding.Unicode.GetString(value) worked - but if that doesn't, please post a sample (in hex) and I'll see what I can do. What does the documentation of whatever's put the data in there say?

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

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



回答2:


I had this problem too and i solved in this way:

I had declared a 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 listbox called "ListRecent" I have obtained the complete list of recent




回答3:


Use

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

Also look at System.Text.Encoding and System.Text.Encoding.Unicode



来源:https://stackoverflow.com/questions/349410/how-can-i-convert-a-reg-binary-value-from-the-registry-into-a-string-vb-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!