# HG changeset patch # User moel.mich # Date 1284492191 0 # Node ID edb59f3745e8d92e1e1feaaf25e2e4b95829b367 # Parent 3ad822f418cb2d7e17b37acc939e520564237e09 Fixed an UnauthorizedAccessException when modifying the auto-startup registry entry. diff -r 3ad822f418cb -r edb59f3745e8 GUI/MainForm.cs --- a/GUI/MainForm.cs Mon Sep 13 22:55:25 2010 +0000 +++ b/GUI/MainForm.cs Tue Sep 14 19:23:11 2010 +0000 @@ -198,7 +198,13 @@ autoStart = new UserOption(null, startupManager.Startup, startupMenuItem, settings); autoStart.Changed += delegate(object sender, EventArgs e) { - startupManager.Startup = autoStart.Value; + try { + startupManager.Startup = autoStart.Value; + } catch (InvalidOperationException) { + MessageBox.Show("Updating the auto-startup option failed.", "Error", + MessageBoxButtons.OK, MessageBoxIcon.Error); + autoStart.Value = startupManager.Startup; + } }; readHddSensors = new UserOption("hddMenuItem", true, hddMenuItem, settings); diff -r 3ad822f418cb -r edb59f3745e8 GUI/StartupManager.cs --- a/GUI/StartupManager.cs Mon Sep 13 22:55:25 2010 +0000 +++ b/GUI/StartupManager.cs Tue Sep 14 19:23:11 2010 +0000 @@ -174,7 +174,7 @@ } private void CreateRegistryRun() { - RegistryKey key = Registry.CurrentUser.CreateSubKey(REGISTRY_RUN); + RegistryKey key = Registry.CurrentUser.CreateSubKey(REGISTRY_RUN); key.SetValue("OpenHardwareMonitor", Application.ExecutablePath); } @@ -192,20 +192,27 @@ return startup; } set { - if (startup != value) { - startup = value; + if (startup != value) { if (isAvailable) { if (scheduler != null) { - if (startup) + if (value) CreateSchedulerTask(); else DeleteSchedulerTask(); + startup = value; } else { - if (startup) - CreateRegistryRun(); - else - DeleteRegistryRun(); + try { + if (value) + CreateRegistryRun(); + else + DeleteRegistryRun(); + startup = value; + } catch (UnauthorizedAccessException) { + throw new InvalidOperationException(); + } } + } else { + throw new InvalidOperationException(); } } }