Exemplo n.º 1
0
        /// <summary>
        /// Removes a Task Scheduler task from the PowerShell/ScheduledJobs folder
        /// based on a task name.
        /// </summary>
        /// <param name="taskName">Task Scheduler task name</param>
        /// <param name="force">Force running instances to stop and remove task</param>
        /// <param name="firstCheckForTask">First check for existence of task</param>
        public void RemoveTaskByName(
            string taskName,
            bool force,
            bool firstCheckForTask)
        {
            // Get registered task.
            IRegisteredTask iRegisteredTask = null;

            try
            {
                iRegisteredTask = _iRootFolder.GetTask(taskName);
            }
            catch (System.IO.DirectoryNotFoundException)
            {
                if (!firstCheckForTask)
                {
                    throw;
                }
            }
            catch (System.IO.FileNotFoundException)
            {
                if (!firstCheckForTask)
                {
                    throw;
                }
            }

            if (iRegisteredTask == null)
            {
                return;
            }

            // Check to see if any instances of this job/task is running.
            IRunningTaskCollection iRunningTasks = iRegisteredTask.GetInstances(0);

            if (iRunningTasks.Count > 0)
            {
                if (!force)
                {
                    string msg = StringUtil.Format(ScheduledJobErrorStrings.CannotRemoveTaskRunningInstance, taskName);
                    throw new ScheduledJobException(msg);
                }

                // Stop all running tasks.
                iRegisteredTask.Stop(0);
            }

            // Remove task.
            _iRootFolder.DeleteTask(taskName, 0);
        }
Exemplo n.º 2
0
        public void RemoveTaskByName(string taskName, bool force, bool firstCheckForTask)
        {
            IRegisteredTask task = null;

            try
            {
                task = this._iRootFolder.GetTask(taskName);
            }
            catch (DirectoryNotFoundException directoryNotFoundException)
            {
                if (!firstCheckForTask)
                {
                    throw;
                }
            }
            catch (FileNotFoundException fileNotFoundException)
            {
                if (!firstCheckForTask)
                {
                    throw;
                }
            }
            if (task != null)
            {
                IRunningTaskCollection instances = task.GetInstances(0);
                if (instances.Count > 0)
                {
                    if (force)
                    {
                        task.Stop(0);
                    }
                    else
                    {
                        string str = StringUtil.Format(ScheduledJobErrorStrings.CannotRemoveTaskRunningInstance, taskName);
                        throw new ScheduledJobException(str);
                    }
                }
                this._iRootFolder.DeleteTask(taskName, 0);
                return;
            }
            else
            {
                return;
            }
        }
Exemplo n.º 3
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()
        {
            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;
            }
        }
Exemplo n.º 5
0
        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;
            }
        }
Exemplo n.º 6
0
 internal RunningTaskEnumerator(TaskService svc, IRunningTaskCollection iTaskColl)
 {
     this.svc = svc;
     v2Svc    = svc.v2TaskService;
     iEnum    = iTaskColl.GetEnumerator();
 }
Exemplo n.º 7
0
 internal RunningTaskCollection(TaskService svc, IRunningTaskCollection iTaskColl)
 {
     this.svc = svc;
     v2Svc    = svc.v2TaskService;
     v2Coll   = iTaskColl;
 }
Exemplo n.º 8
0
 internal RunningTaskCollection(TaskService svc, IRunningTaskCollection iTaskColl)
 {
     _svc    = svc;
     _v2Svc  = svc._v2TaskService;
     _v2Coll = iTaskColl;
 }
Exemplo n.º 9
0
 internal RunningTaskEnumerator(TaskService svc, IRunningTaskCollection iTaskColl)
 {
     _svc   = svc;
     _v2Svc = svc._v2TaskService;
     _iEnum = iTaskColl.GetEnumerator();
 }