diff -r 3ef997c53b50 -r 912a06e2bd53 GUI/StartupManager.cs --- a/GUI/StartupManager.cs Thu May 20 21:23:54 2010 +0000 +++ b/GUI/StartupManager.cs Fri May 21 17:28:52 2010 +0000 @@ -38,6 +38,7 @@ using System; using System.Collections.Generic; using System.IO; +using System.Security.Principal; using System.Windows.Forms; using Microsoft.Win32; using OpenHardwareMonitor.TaskScheduler; @@ -51,25 +52,39 @@ private const string REGISTRY_RUN = @"Software\Microsoft\Windows\CurrentVersion\Run"; + private bool IsAdministrator() { + try { + WindowsIdentity identity = WindowsIdentity.GetCurrent(); + WindowsPrincipal principal = new WindowsPrincipal(identity); + return principal.IsInRole(WindowsBuiltInRole.Administrator); + } catch { + return false; + } + } + public StartupManager() { - try { - scheduler = new TaskSchedulerClass(); - scheduler.Connect(null, null, null, null); - } catch { + if (IsAdministrator()) { + try { + scheduler = new TaskSchedulerClass(); + scheduler.Connect(null, null, null, null); + } catch { + scheduler = null; + } + + if (scheduler != null) { + try { + ITaskFolder folder = scheduler.GetFolder("\\Open Hardware Monitor"); + IRegisteredTask task = folder.GetTask("Startup"); + startup = task != null; + } catch (IOException) { + startup = false; + } catch (UnauthorizedAccessException) { + scheduler = null; + } + } + } else { scheduler = null; } - - if (scheduler != null) { - try { - ITaskFolder folder = scheduler.GetFolder("\\Open Hardware Monitor"); - IRegisteredTask task = folder.GetTask("Startup"); - startup = task != null; - } catch (IOException) { - startup = false; - } catch (UnauthorizedAccessException) { - scheduler = null; - } - } if (scheduler == null) { RegistryKey key = Registry.CurrentUser.OpenSubKey(REGISTRY_RUN);