十六进制格式的注册表二进制文件 [英] Registry Binary In Hex Format
问题描述
我有一个程序,它在1个组合框中列出了许可证的位置,并在另一个组合框中列出了值的名称.
然后,在第二个中选择一个名称,然后单击一个按钮以返回键中的数据.
这是Regbinary.
唯一的问题是,返回的不是十六进制格式(如通过regedit查看),而是返回十进制.
我也想将十六进制输出到文本框中.
谁能告诉我为什么这段代码将返回十进制而不是十六进制,甚至是二进制吗?
我已经通过将regedit中看到的每个字节转换为程序中显示的结果来验证代码的工作.
感谢您的宝贵时间.
I have a program that list the locations of License in 1 combobox and list the names of the Values in another Combobox.
I then select a name in the second, then hit a button to return the data in the key.
It is Regbinary.
Only problem is What is returned is not the hex format like viewing thru regedit but it is returning decimal.
I would like to output the hex into a textbox also.
Would Anyone tell me why this code would return Decimal instead of hex, or even binary ?
I have verified the Code works by Converting each byte seen in regedit to the Result Displayed in my program.
Thanks for your Time.
Try
Dim strbldr As New StringBuilder
Dim regbinary() As Byte
Dim LicenseNumber As String
LicenseNumber = ComboBoxKeyValueName.SelectedItem.ToString
If ComboBoxLicLocation.SelectedItem = LicKey1 Then
SelectedRegLocation = LicKey1.ToString
regbinary = (Registry.LocalMachine.OpenSubKey( _
"SOFTWARE\Wow6432Node\Licenses").GetValue(LicenseNumber))
ElseIf ComboBoxLicLocation.SelectedItem = LicKey2 Then
SelectedRegLocation = LicKey2.ToString
regbinary = (Registry.LocalMachine.OpenSubKey( _
"SOFTWARE\Licenses").GetValue(LicenseNumber))
ElseIf ComboBoxLicLocation.SelectedItem = LicKey3 Then
SelectedRegLocation = LicKey3.ToString
regbinary = (Registry.CurrentUser.OpenSubKey( _
"Software\Licenses").GetValue(LicenseNumber))
End If
For Each strbyte In regbinary
strbldr.Append(strbyte & ",")
Next
txtbxOutputDecimalArray.Text = strbldr.ToString
lblCount.Text = "Number of bytes : " & regbinary.Count.ToString
Registry.LocalMachine.Close()
Catch ex As Exception
End Try
推荐答案
查看对GetValue
的描述: ^ ].
返回类型为System.Object
.这是返回对象的编译时类型,而具体运行时类型取决于键.您可以通过调用GetValueKind
, http了解如何将此值强制转换为哪种类型. ://msdn.microsoft.com/en-us/library/microsoft.win32.registrykey.getvaluekind.aspx [string.Format,请参见:
http://msdn.microsoft.com/en-us/library/system.string. format.aspx [^ ],
http://msdn.microsoft.com/en-us/library/dwhawy9k.aspx [ ^ ],
http://msdn.microsoft.com/en-us/library/0c899ak8.aspx [ ^ ].
—SA
Look at the description ofGetValue
: http://msdn.microsoft.com/en-us/library/fdf576x1.aspx[^].
The return type ifSystem.Object
. This is a compile-time type of the returned object, and the concrete run-time type depends on the key. You can learn what type this value should be cast to by callingGetValueKind
, http://msdn.microsoft.com/en-us/library/microsoft.win32.registrykey.getvaluekind.aspx[^].
You always need to validate the value type. You don''t do it; and this is your big mistake.
Now, if the returned value is really numeric or binary (as your code suggests), it simply cannot be decimal or hexadecimal — it''s binary. If you don''t understand it, you should start your computer education pretty much from the very beginning. You problem is not that you don''t know how to show the data correctly, your problem is that your question makes no sense as it is based on misunderstanding of data representation, as far as I can see from your question — any data.
Decimal or hexadecimal is only related to string representation of binary data (any numeric type is also binary). You can present it in a string in many different ways, but the data remains the same. Appending bytes toStringBuilder
make little sense. You can present your binary data in the form of array of bytes in many different ways and different order; all of them are equally correct but should come with some "legend". A hint: usestring.Format
, see:
http://msdn.microsoft.com/en-us/library/system.string.format.aspx[^],
http://msdn.microsoft.com/en-us/library/dwhawy9k.aspx[^],
http://msdn.microsoft.com/en-us/library/0c899ak8.aspx[^].
—SA
使用此处代码中的想法
http://msdn.microsoft.com/en-us /library/microsoft.win32.registryvaluekind(v=VS.90).aspx [ 返回的结果与Regedit中显示的结果相同.
参见下面的代码,在创建按钮的单击事件中对输出进行注释.
再次感谢您向正确的方向推动我.
注意:请注意所发布代码中的换行.
Using the Idea from the code on the page here
http://msdn.microsoft.com/en-us/library/microsoft.win32.registryvaluekind(v=VS.90).aspx[^]
I was able to create another test project. 1 textbox and 5 buttons.
By Working with the Format I could change the way the output looked, by adding spaces or the comma to "{0:X2}," .I still had to use the Stringbuilder Because I don''t know of another way to get the array into a textbox without building the string.
The result returned is the same that shows up in Regedit.
See the code below, the output is commented in the button click event it was created in.
Thanks again for pushing me in the right direction.
Note: Watch out for line wrapping in the posted code.
Imports System
Imports Microsoft.Win32
Imports System.Text
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim strbldr As New Stringbuilder
Dim regbinary() As Byte
regbinary = (Registry.CurrentUser.OpenSubKey("Software\Licenses").GetValue("{R7C0DB872A3F777C0}"))
For Each strbyte In regbinary
strbldr.AppendFormat("{0:X2} ", strbyte)
Next ''returns 2F 59 41 42
TextBox1.Text = strbldr.ToString
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim strbldr As New StringBuilder
Dim regbinary() As Byte
regbinary = (Registry.CurrentUser.OpenSubKey("Software\Licenses").GetValue("{R7C0DB872A3F777C0}"))
For Each strbyte In regbinary
strbldr.AppendFormat("{0:X2}", strbyte)
Next ''Returns 2F594142
TextBox1.Text = strbldr.ToString
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim strbldr As New StringBuilder
Dim regbinary() As Byte
regbinary = (Registry.CurrentUser.OpenSubKey("Software\Licenses").GetValue("{R7C0DB872A3F777C0}"))
For Each strbyte In regbinary
strbldr.AppendFormat("{0:X2} ", strbyte & ",")
Next ''Returns 47, 89, 65, 66,
TextBox1.Text = strbldr.ToString
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
Dim strbldr As New StringBuilder
Dim regbinary() As Byte
regbinary = (Registry.CurrentUser.OpenSubKey("Software\Licenses").GetValue("{R7C0DB872A3F777C0}"))
For Each strbyte In regbinary
strbldr.AppendFormat("{0:X2},", strbyte)
Next ''Returns 2F,59,41,42,
TextBox1.Text = strbldr.ToString
End Sub
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
Dim strbldr As New StringBuilder
Dim regbinary() As Byte
regbinary = (Registry.CurrentUser.OpenSubKey("Software\Licenses").GetValue("{R7C0DB872A3F777C0}"))
For i As Integer = 0 To regbinary.Length - 1
'' Display each byte as two hexadecimal digits.
strbldr.AppendFormat("{0:X2}", regbinary(i))
Next ''Returns 2F594142
TextBox1.Text = strbldr.ToString
End Sub
End Class
这篇关于十六进制格式的注册表二进制文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!