esteuart Posted August 12, 2003 Posted August 12, 2003 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! Quote
Madz Posted August 12, 2003 Posted August 12, 2003 Do you have Administrative access to PC. if not you will not be able to modify registry. also check my example at http://www.xtremedotnettalk.com/showthread.php?s=&threadid=69856 Quote The one and only Dr. Madz eee-m@il
BrianHansen Posted August 26, 2003 Posted August 26, 2003 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). Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.