Beispiel #1
0
        public static bool IsAdminLaunchTaskAlreadyRunning(string appTaskId = "")
        {
            try
            {
                if (appTaskId == null || appTaskId.Length == 0)
                {
                    string exeName = System.IO.Path.GetFileNameWithoutExtension(System.Reflection.Assembly.GetExecutingAssembly().Location);
                    appTaskId = "Run" + exeName + "InAdminMode";
                }

                tsEngine.TaskScheduler ts = new tsEngine.TaskScheduler();
                ts.Connect(null, null, null, null);
                if (ts.Connected)
                {
                    foreach (tsEngine.IRunningTask td in ts.GetRunningTasks(0))
                    {
                        if (td.Name == appTaskId)
                        {
                            return(true);
                        }
                    }
                }
            }
            catch { }
            return(false);
        }
Beispiel #2
0
        /// <summary>
        /// Process record.
        /// </summary>
        protected override void ProcessRecord()
        {
            ITaskService service = new TaskScheduler.TaskScheduler();

            service.Connect();
            foreach (var running_task in service.GetRunningTasks((int)_TASK_ENUM_FLAGS.TASK_ENUM_HIDDEN).Cast <IRunningTask>())
            {
                try
                {
                    ITaskFolder     folder = service.GetFolder(Path.GetDirectoryName(running_task.Path));
                    IRegisteredTask task   = folder.GetTask(running_task.Name);
                    WriteObject(new RunningScheduledTaskEntry(running_task, task));
                }
                catch
                {
                }
            }
        }