简体   繁体   English

如何将注册表中的REG_BINARY值转换为字符串? (vb.net)

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

I have a registry value which is stored as a binary value (REG_BINARY) holding information about a filepath. 我有一个注册表值,该值存储为二进制值(REG_BINARY),其中包含有关文件路径的信息。 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. 我已经阅读了有关system.text.encoding.ASCII.GetString(value)的信息,但这不起作用。 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. 据我所知,注册表值是任意的二进制数据,而不是ASCII,这是产生无用数据的方法的原因。

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: 由于regedit,这应该是:

............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. 该条目本身是从Outlook创建的。 It's an entry for an disabled addin item (resiliency) 这是一个禁用的插件项目(弹性)的条目

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. 如果Encoding.Unicode.GetString(value)工作正常,我不会感到惊讶-否则,请发布一个示例(以十六进制表示),然后我会做些什么。 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是您的朋友,但从字节12开始。

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

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 因此,在名为“ ListRecent”的列表框中,我获得了最近的完整列表

Use 采用

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

Also look at System.Text.Encoding and System.Text.Encoding.Unicode 还要看看System.Text.EncodingSystem.Text.Encoding.Unicode

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM