The following code causes an error but should work. Any ideas? The same code (originally in REALbasic) does work so the currentuser (also an admin on the pc) does have access to write to the registry.
A first chance exception of type 'System.UnauthorizedAccessException' occurred in mscorlib.dll
err> Cannot write to the registry key.
stack>
at System.ThrowHelper.ThrowUnauthorizedAccessException(ExceptionResource resource)
at Microsoft.Win32.RegistryKey.EnsureWriteable()
at Microsoft.Win32.RegistryKey.SetValue(String name, Object value, RegistryValueKind valueKind)
at Microsoft.Win32.RegistryKey.SetValue(String name, Object value)
at ConnectionTools.mMiscFunction.SavePreference(String pref, String value) in mMiscFunction.vb:line 92
VB.NET:
Public Sub SavePreference(ByVal pref As String, ByVal value As String)
Dim tmp As RegistryKey = Registry.CurrentUser
Dim tmp2 As RegistryKey
tmp2 = tmp.OpenSubKey("SOFTWARE\Connection Tools")
If tmp2 Is Nothing Then
tmp.CreateSubKey("SOFTWARE\Connection Tools")
tmp2 = tmp.OpenSubKey("SOFTWARE\Connection Tools")
End If
If tmp2 IsNot Nothing Then tmp2.SetValue(pref, LCase(value))
End Sub
A first chance exception of type 'System.UnauthorizedAccessException' occurred in mscorlib.dll
err> Cannot write to the registry key.
stack>
at System.ThrowHelper.ThrowUnauthorizedAccessException(ExceptionResource resource)
at Microsoft.Win32.RegistryKey.EnsureWriteable()
at Microsoft.Win32.RegistryKey.SetValue(String name, Object value, RegistryValueKind valueKind)
at Microsoft.Win32.RegistryKey.SetValue(String name, Object value)
at ConnectionTools.mMiscFunction.SavePreference(String pref, String value) in mMiscFunction.vb:line 92
Last edited: