I'm trying to make something to clean my registry periodically and at an point, i need to read a value of one registry key, and it's there i'm having problems. The value is in BYTE (Hex) and i can't read it. Here's my code:
'function that i'm using to check if registry value exists and read it...
Public Function RegValue(ByVal Hive As RegistryHive, ByVal Key As String, ByVal ValueName As String, ByRef ErrInfo As String) As String
Dim objParent As RegistryKey
Dim objSubkey As RegistryKey
Dim sAns As String
Select Case Hive
Case RegistryHive.ClassesRoot
objParent = Registry.ClassesRoot
Case RegistryHive.CurrentConfig
objParent = Registry.CurrentConfig
Case RegistryHive.CurrentUser
objParent = Registry.CurrentUser
Case RegistryHive.DynData
objParent = Registry.DynData
Case RegistryHive.LocalMachine
objParent = Registry.LocalMachine
Case RegistryHive.PerformanceData
objParent = Registry.PerformanceData
Case RegistryHive.Users
objParent = Registry.Users
End Select
Try
objSubkey = objParent.OpenSubKey(Key)
'if can't be found, object is not initialized
If Not objSubkey Is Nothing Then
sAns = (objSubkey.GetValue(ValueName))
End If
Catch ex As Exception
ErrInfo = ex.Message
Finally
'if no error but value is empty, populate errinfo
If ErrInfo = "" And sAns = "" Then
ErrInfo = "No value found for requested registry key"
End If
End Try
Return sAns
End Function
' Button click that tries to read the value
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim sAns As String
Dim sErr As String = ""
sAns = RegValue(RegistryHive.ClassesRoot, "Local Settings\Software\Microsoft\Windows\Shell\BagMRU\0\0\0\0\2\0\0\0\0\0", "0", sErr)
If sAns <> "" Then
MsgBox("Value = " & sAns)
Else
MsgBox("This error occurred: " & sErr)
End If
End Sub
When i run it and try to read the value, i get this message:
"This error occurred: The conversion of type 'Byte ()' to type 'String' is not valid."
There's a image of the registry value that i'm trying to read:
If someone can help, i would be thankful.