1

我正在尝试在 Visual Basic 2012 中构建一个应用程序,该应用程序将从注册表项读取多个值及其数据,并将十六进制转换为 ascii,然后输出到列表框。

即“HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\RecentDocs”将有任何最近文件的多个条目。

我遇到的问题是每次代码运行时它都可以很好地读取数据,我相信它正在从十六进制转换为 ascii ok,但它只会输出每个十六进制转换的第一个字母。

这是代码

Imports Microsoft.Win32
Imports System.Windows.Forms.VisualStyles.VisualStyleElement.Status

Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) andles MyBase.Load
        Dim regkeyRunMRU As RegistryKey = Registry.CurrentUser.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Explorer\RecentDocs", False)
        Dim w As Object = regkeyRunMRU.GetValueNames()
        For Each s In w
            If s <> "MRUList" Then
                ListBox1.Items.Add(GetREG_BINARY(regkeyRunMRU.ToString, s))
            End If
        Next
    End Sub

    Public Function GetREG_BINARY(ByVal Path As String, ByVal Value As String) As String

        Dim Data() As Byte = CType(Microsoft.Win32.Registry.GetValue(Path, Value, Nothing), Byte())
        If Data Is Nothing Then Return "N/A"
        Dim Result As String = String.Empty
        For j As Integer = 0 To Data.Count - 1
            Result &= Hex(Data(j)).PadLeft(2, "0"c) & " "
        Next

        Dim sResult = Result.Replace(" ", "")
        Dim strTemp As String
        Dim strReturn As String
        Dim I As Long
        For I = 1 To Len(sResult) Step 2
            strTemp = Chr(Val("&H" & Mid$(sResult, I, 2)))
            strReturn = strReturn & strTemp
        Next I
        Return strReturn
    End Function


End Class           
4

0 回答 0