Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I need my stand-alone application to both read and write to the registry. I have no problems reading from the registry, but whenever I try to save my keys to the registry I get the following error:

 

An unhandled exception of type 'System.UnauthorizedAccessException' occurred in mscorlib.dll

Additional information: Cannot write to the registry key.

 

I assume it has something to do with security permissions - I don't know. If it is a security issue, how do I give my application permission to update the registry?

 

Here is the code

Private key As Microsoft.Win32.RegistryKey
Private Const KEY_LOCATION = "Software\Company\Product"

Public Sub New()
       key = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(KEY_LOCATION)
End Sub

Private Sub frmService_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
       tbBroadcast.Text = key.GetValue("Broadcast", "")
       tbBgPath.Text = key.GetValue("InstallLocation", "")
       nudTimer.Value = key.GetValue("TimerLength", 10)
End Sub

Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
       key.SetValue("Broadcast", tbBroadcast.Text)
       key.SetValue("InstallLocation", tbBgPath.Text)
       key.SetValue("TimerLength", nudTimer.Value)
End Sub

 

The program dies on key.SetValue("Broadcast", tbBroadcast.Text).

 

Please help!

  • 2 weeks later...
Posted

Try this

 

 

Public Sub New()
       key = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(KEY_LOCATION, TRUE)
End Sub

 

Note the True, which sets, if the registry is read-only or read-write (default is False = read-only).

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...