Since none of my other solutions have worked, I turned to google. I found this:
http://www.codeproject.com/Questions/51647/can-t-write-to-registry-in-currentuser
Problem:
The following code causes an error but should work. Why doesn't it work? 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.
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\example")
If tmp2 Is Nothing Then
tmp.CreateSubKey("SOFTWARE\example")
tmp2 = tmp.OpenSubKey("SOFTWARE\example")
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
First solution:
You're using the wrong overload of Registry.OpenSubkey[^]. Registry.OpenSubkey(String) opens as read-only. Use RegistryKey.OpenSubKey(String, Boolean) instead. ie:
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\example", True)
If tmp2 Is Nothing Then
tmp.CreateSubKey("SOFTWARE\example")
tmp2 = tmp.OpenSubKey("SOFTWARE\example", True)
End If
If tmp2 IsNot Nothing Then tmp2.SetValue(pref, LCase(value))
End Sub
I put it in a code box as to not confuse what I'm saying and what I found. While I do NOT recommend messing with registry keys, this seems to be a solution that may work.
I got to that link by searching: Can't write to registry Java, and you'll notice that the posted problem is from 2010. But it's a start, and google seems to be the way to find some answers for you guys.
Again, I do NOT recommend messing with registry keys. Try to find a different way to do it, and don't blame me if you do and screw it up.