I have a program that reads and writes values to the registry.
My program works just fine on windows t but not on windows 8.
the function I use is as follows:
If the entry does not exist it creates the entry and sets the value. On windows 8 I get the following error
System.NullReferenceException was unhandled
HResult=-2147467261
Message=Object reference not set to an instance of an object.
Why does this work differently in windows 8?
Does anyone have a solution?
Thanks in advance
Pinto
My program works just fine on windows t but not on windows 8.
the function I use is as follows:
Public Function ReadRegistryValue(ByVal MainKey As RegistryKey, ByVal sKey As String, ByVal sKeyName As String, _
ByRef oNameValue As Object) As String
Dim rkKey As RegistryKey
Dim Value As New String("")
Try
'open the given subkey
rkKey = MainKey.OpenSubKey(sKey, True)
'check to see if the subkey exists
If rkKey Is Nothing Then 'it doesnt exist
'throw an exception
rkKey = MainKey.CreateSubKey(sKey, RegistryKeyPermissionCheck.Default)
'set the value of the subkey
rkKey.SetValue(sKeyName, oNameValue, RegistryValueKind.String)
'Throw New Exception("The Registry SubKey provided doesnt exist!")
End If
'get the value
oNameValue = rkKey.GetValue(sKeyName)
Value = oNameValue.ToString
Catch ex As Exception
MessageBox.Show(ex.Message, "Error: Reading Registry Value", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
Return Value
End Function
If the entry does not exist it creates the entry and sets the value. On windows 8 I get the following error
System.NullReferenceException was unhandled
HResult=-2147467261
Message=Object reference not set to an instance of an object.
Why does this work differently in windows 8?
Does anyone have a solution?
Thanks in advance
Pinto
Last edited by a moderator: