如何将注册表中的 REG_BINARY 值转换为字符串?(vb.net)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/349410/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I convert a REG_BINARY value from the registry into a string ? (vb.net)
提问by Marcus
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?
我有一个注册表值,它存储为一个二进制值 (REG_BINARY),其中包含有关文件路径的信息。该值被读出到一个字节数组中。但是我怎样才能把它转换成一个可读的字符串呢?
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.
我已经阅读了 system.text.encoding.ASCII.GetString(value) 但这不起作用。据我所知,注册表值是任意二进制数据,而不是 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. It's an entry for an disabled addin item (resiliency)
条目本身是从 Outlook 创建的。这是禁用插件项(弹性)的条目
回答by Jon Skeet
Well, it's not arbitrarybinary data - it's text data in somekind 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?
如果Encoding.Unicode.GetString(value)有效,我不会感到惊讶- 但如果没有,请发布示例(十六进制),我会看看我能做什么。将数据放入其中的任何文件的文档说明了什么?
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)
回答by Roberto
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”的列表框中,我获得了最近的完整列表
回答by abatishchev
Use
用
Function Microsoft.Win32.RegistryKey.GetValue(name as String) as Object
Also look at System.Text.Encodingand System.Text.Encoding.Unicode
还看看System.Text.Encoding和System.Text.Encoding.Unicode

