[SOLVED][2005] Reg_multi_sz
After an extensive search trough our worlwide encyclopedia I have to bother you all, my apologies, but here goes;
I'm trying to read an REG_MULTI_SZ registry key, I already know how to write it, but it flakes on the reading part, here is how far I got:
Code:
Dim key As Microsoft.Win32.RegistryKey
key = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("SYSTEM\Program\Attr\")
If key IsNot Nothing Then
Dim strNotes() As String
strNotes = CType(key.GetValue("Notes"), String())
If strNotes IsNot Nothing Then
For X = 0 To UBound(strNotes)
strInfo = strInfo & vbCrLf & strNotes(X)
Next
End If
I get this error:
"Unable to cast object of type 'System.String' to type 'System.String[]'
But I'm sure the regvalue is a array, so I'm a bit confused.
Could you help me with some suggestions?
Kind Regards, Starf0x
Re: [SOLVED][2005] Reg_multi_sz
I would tend to disagree a bit here. I would not get the data and then test its type. A REG_MULTI_SZ is going to be returned as a String array EVERY time. If you know that the Registry value you're retrieving is a REG_MULTI_SZ then you know it will be returned as a String array. If you aren't 100% sure what the type of the value you're retrieving is then you can use the GetValueKind method:
vb.net Code:
Dim key As RegistryKey = Registry.LocalMachine.OpenSubKey("key path here")
Select Case key.GetValueKind("value name here")
Case RegistryValueKind.String
'The value is type REG_SZ and will be returned as a String.
Case RegistryValueKind.MultiString
'The value is type REG_MULTI_SZ and will be returned as a String array.
'And so on for the other types.
End Select
Re: [SOLVED][2005] Reg_multi_sz
Quote:
Originally Posted by jmcilhinney
I would tend to disagree a bit here. I would not get the data and then test its type. A REG_MULTI_SZ is going to be returned as a String array EVERY time. If you know that the Registry value you're retrieving is a REG_MULTI_SZ then you know it will be returned as a String array. If you aren't 100% sure what the type of the value you're retrieving is then you can use the GetValueKind method
This is a good approach, I'll use this to approach my problem, Thank you
Kind Regards, Starf0x