public StartupManager()
        {
            int p = (int)Environment.OSVersion.Platform;

            if ((p == 4) || (p == 128))
            {
                _scheduler  = null;
                IsAvailable = false;
                return;
            }

            if (IsAdministrator())
            {
                try
                {
                    _scheduler = new TaskSchedulerClass();
                    _scheduler.Connect(null, null, null, null);
                }
                catch
                {
                    _scheduler = null;
                }

                if (_scheduler != null)
                {
                    try
                    {
                        // check if the taskscheduler is running
                        IRunningTaskCollection _      = _scheduler.GetRunningTasks(0);
                        ITaskFolder            folder = _scheduler.GetFolder("\\Open Hardware Monitor");
                        IRegisteredTask        task   = folder.GetTask("Startup");
                        _startup = (task != null) && (task.Definition.Triggers.Count > 0) &&
                                   (task.Definition.Triggers[1].Type == TASK_TRIGGER_TYPE2.TASK_TRIGGER_LOGON) &&
                                   (task.Definition.Actions.Count > 0) &&
                                   (task.Definition.Actions[1].Type == TASK_ACTION_TYPE.TASK_ACTION_EXEC) &&
                                   (task.Definition.Actions[1] is IExecAction) && (((IExecAction)task.Definition.Actions[1]).Path == Application.ExecutablePath);
                    }
                    catch (IOException)
                    {
                        _startup = false;
                    }
                    catch (UnauthorizedAccessException)
                    {
                        _scheduler = null;
                    }
                    catch (COMException)
                    {
                        _scheduler = null;
                    }
                }
            }
            else
            {
                _scheduler = null;
            }

            if (_scheduler == null)
            {
                try
                {
                    using (RegistryKey key = Registry.CurrentUser.OpenSubKey(REGISTRY_RUN))
                    {
                        _startup = false;
                        string value = (string)key?.GetValue("LibreHardwareMonitor");

                        if (value != null)
                        {
                            _startup = value == Application.ExecutablePath;
                        }
                    }
                    IsAvailable = true;
                }
                catch (SecurityException)
                {
                    IsAvailable = false;
                }
            }
            else
            {
                IsAvailable = true;
            }
        }
Example #2
0
        public StartupManager()
        {
            int p = (int)System.Environment.OSVersion.Platform;

            if ((p == 4) || (p == 128))
            {
                scheduler   = null;
                isAvailable = false;
                return;
            }

            if (IsAdministrator())
            {
                try
                {
                    scheduler = new TaskSchedulerClass();
                    scheduler.Connect(null, null, null, null);
                }
                catch
                {
                    scheduler = null;
                }

                if (scheduler != null)
                {
                    try
                    {
                        // check if the task scheduler is running
                        IRunningTaskCollection collection = scheduler.GetRunningTasks(0);

                        ITaskFolder     folder = scheduler.GetFolder("\\Sharp Display Manager");
                        IRegisteredTask task   = folder.GetTask("Startup");
                        startup = (task != null) &&
                                  (task.Definition.Triggers.Count > 0) &&
                                  (task.Definition.Triggers[1].Type ==
                                   TASK_TRIGGER_TYPE2.TASK_TRIGGER_LOGON) &&
                                  (task.Definition.Actions.Count > 0) &&
                                  (task.Definition.Actions[1].Type ==
                                   TASK_ACTION_TYPE.TASK_ACTION_EXEC) &&
                                  (task.Definition.Actions[1] as IExecAction != null) &&
                                  ((task.Definition.Actions[1] as IExecAction).Path ==
                                   Application.ExecutablePath);
                    }
                    catch (IOException)
                    {
                        startup = false;
                    }
                    catch (UnauthorizedAccessException)
                    {
                        scheduler = null;
                    }
                    catch (COMException)
                    {
                        scheduler = null;
                    }
                }
            }
            else
            {
                scheduler = null;
            }

            if (scheduler == null)
            {
                try
                {
                    using (RegistryKey key =
                               Registry.CurrentUser.OpenSubKey(REGISTRY_RUN))
                    {
                        startup = false;
                        if (key != null)
                        {
                            string value = (string)key.GetValue("SharpDisplayManager");
                            if (value != null)
                            {
                                startup = value == LaunchCommand;
                            }
                        }
                    }
                    isAvailable = true;
                }
                catch (SecurityException)
                {
                    isAvailable = false;
                }
            }
            else
            {
                isAvailable = true;
            }
        }
        public StartupManager()
        {
            if (Hardware.OperatingSystem.IsUnix)
            {
                scheduler   = null;
                isAvailable = false;
                return;
            }

            if (IsAdministrator())
            {
                try {
                    scheduler = new TaskSchedulerClass();
                    scheduler.Connect(null, null, null, null);
                } catch {
                    scheduler = null;
                }

                if (scheduler != null)
                {
                    try {
                        try {
                            // check if the taskscheduler is running
                            IRunningTaskCollection collection = scheduler.GetRunningTasks(0);
                        } catch (ArgumentException) { }

                        ITaskFolder     folder = scheduler.GetFolder("\\Open Hardware Monitor");
                        IRegisteredTask task   = folder.GetTask("Startup");
                        startup = (task != null) &&
                                  (task.Definition.Triggers.Count > 0) &&
                                  (task.Definition.Triggers[1].Type ==
                                   TASK_TRIGGER_TYPE2.TASK_TRIGGER_LOGON) &&
                                  (task.Definition.Actions.Count > 0) &&
                                  (task.Definition.Actions[1].Type ==
                                   TASK_ACTION_TYPE.TASK_ACTION_EXEC) &&
                                  (task.Definition.Actions[1] as IExecAction != null) &&
                                  ((task.Definition.Actions[1] as IExecAction).Path ==
                                   Application.ExecutablePath);
                    } catch (IOException) {
                        startup = false;
                    } catch (UnauthorizedAccessException) {
                        scheduler = null;
                    } catch (COMException) {
                        scheduler = null;
                    } catch (NotImplementedException) {
                        scheduler = null;
                    }
                }
            }
            else
            {
                scheduler = null;
            }

            if (scheduler == null)
            {
                try {
                    using (RegistryKey key =
                               Registry.CurrentUser.OpenSubKey(REGISTRY_RUN)) {
                        startup = false;
                        if (key != null)
                        {
                            string value = (string)key.GetValue("OpenHardwareMonitor");
                            if (value != null)
                            {
                                startup = value == Application.ExecutablePath;
                            }
                        }
                    }
                    isAvailable = true;
                } catch (SecurityException) {
                    isAvailable = false;
                }
            }
            else
            {
                isAvailable = true;
            }
        }