diff --git a/GUI/MainForm.cs b/GUI/MainForm.cs index a6083d1..0fd395e 100644 --- a/GUI/MainForm.cs +++ b/GUI/MainForm.cs @@ -198,7 +198,13 @@ namespace OpenHardwareMonitor.GUI { 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 --git a/GUI/StartupManager.cs b/GUI/StartupManager.cs index 54423be..aff1abd 100644 --- a/GUI/StartupManager.cs +++ b/GUI/StartupManager.cs @@ -174,7 +174,7 @@ namespace OpenHardwareMonitor.GUI { } 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 @@ namespace OpenHardwareMonitor.GUI { 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(); } } }