From 2b64de788bc74f611eaaf3900f5e3cbbe6796263 Mon Sep 17 00:00:00 2001 From: Matt Robinson Date: Sun, 12 Oct 2014 16:11:45 +0100 Subject: [PATCH] Ignore access denied to set run on startup If the user doesn't have write access (or their AV is preventing access) to SOFTWARE\Microsoft\Windows\CurrentVersion\Run, ignore the problem gracefully instead of crashing. --- Classes/OsUtils.cs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Classes/OsUtils.cs b/Classes/OsUtils.cs index cc1263dd..a374a06c 100644 --- a/Classes/OsUtils.cs +++ b/Classes/OsUtils.cs @@ -183,7 +183,17 @@ internal static bool CompositionEnabled() internal static void ApplyRunOnStartup() { - RegistryKey runKey = Registry.CurrentUser.CreateSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run"); + RegistryKey runKey; + + try + { + runKey = Registry.CurrentUser.CreateSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run"); + } + catch (UnauthorizedAccessException) + { + // Access denied by non-standard ACL or antivirus + return; + } if (Settings.RunOnStartup) {