示例#1
0
        private void AddTaskOptions(ITaskDefinition iTaskDefinition, ScheduledJobOptions jobOptions)
        {
            _TASK_RUNLEVEL variable;

            iTaskDefinition.Settings.DisallowStartIfOnBatteries = !jobOptions.StartIfOnBatteries;
            iTaskDefinition.Settings.StopIfGoingOnBatteries     = jobOptions.StopIfGoingOnBatteries;
            iTaskDefinition.Settings.WakeToRun     = jobOptions.WakeToRun;
            iTaskDefinition.Settings.RunOnlyIfIdle = !jobOptions.StartIfNotIdle;
            iTaskDefinition.Settings.IdleSettings.StopOnIdleEnd = jobOptions.StopIfGoingOffIdle;
            iTaskDefinition.Settings.IdleSettings.RestartOnIdle = jobOptions.RestartOnIdleResume;
            iTaskDefinition.Settings.IdleSettings.IdleDuration  = ScheduledJobWTS.ConvertTimeSpanToWTSString(jobOptions.IdleDuration);
            iTaskDefinition.Settings.IdleSettings.WaitTimeout   = ScheduledJobWTS.ConvertTimeSpanToWTSString(jobOptions.IdleTimeout);
            iTaskDefinition.Settings.Hidden = !jobOptions.ShowInTaskScheduler;
            iTaskDefinition.Settings.RunOnlyIfNetworkAvailable = !jobOptions.RunWithoutNetwork;
            iTaskDefinition.Settings.AllowDemandStart          = !jobOptions.DoNotAllowDemandStart;
            iTaskDefinition.Settings.MultipleInstances         = this.ConvertFromMultiInstances(jobOptions.MultipleInstancePolicy);
            TaskScheduler.IPrincipal principal = iTaskDefinition.Principal;
            if (jobOptions.RunElevated)
            {
                variable = _TASK_RUNLEVEL.TASK_RUNLEVEL_HIGHEST;
            }
            else
            {
                variable = _TASK_RUNLEVEL.TASK_RUNLEVEL_LUA;
            }
            principal.RunLevel = variable;
        }
示例#2
0
        private CimInstance ConvertToOnce(ScheduledJobTrigger trigger, CimSession cimSession)
        {
            CimClass    cimClass    = cimSession.GetClass(CIM_TRIGGER_NAMESPACE, "MSFT_TaskTimeTrigger");
            CimInstance cimInstance = new CimInstance(cimClass);

            cimInstance.CimInstanceProperties["RandomDelay"].Value = ScheduledJobWTS.ConvertTimeSpanToWTSString(trigger.RandomDelay);

            if (trigger.RepetitionInterval != null && trigger.RepetitionDuration != null)
            {
                CimClass    cimRepClass    = cimSession.GetClass(CIM_TRIGGER_NAMESPACE, "MSFT_TaskRepetitionPattern");
                CimInstance cimRepInstance = new CimInstance(cimRepClass);

                cimRepInstance.CimInstanceProperties["Interval"].Value = ScheduledJobWTS.ConvertTimeSpanToWTSString(trigger.RepetitionInterval.Value);

                if (trigger.RepetitionDuration == TimeSpan.MaxValue)
                {
                    cimRepInstance.CimInstanceProperties["StopAtDurationEnd"].Value = false;
                }
                else
                {
                    cimRepInstance.CimInstanceProperties["StopAtDurationEnd"].Value = true;
                    cimRepInstance.CimInstanceProperties["Duration"].Value          = ScheduledJobWTS.ConvertTimeSpanToWTSString(trigger.RepetitionDuration.Value);
                }

                cimInstance.CimInstanceProperties["Repetition"].Value = cimRepInstance;
            }

            AddCommonProperties(trigger, cimInstance);
            return(cimInstance);
        }
        private CimInstance ConvertToAtStartup(ScheduledJobTrigger trigger, CimSession cimSession)
        {
            CimClass    @class      = cimSession.GetClass(JobTriggerToCimInstanceConverter.CIM_TRIGGER_NAMESPACE, "MSFT_TaskBootTrigger");
            CimInstance cimInstance = new CimInstance(@class);

            cimInstance.CimInstanceProperties["Delay"].Value = ScheduledJobWTS.ConvertTimeSpanToWTSString(trigger.RandomDelay);
            JobTriggerToCimInstanceConverter.AddCommonProperties(trigger, cimInstance);
            return(cimInstance);
        }
示例#4
0
        private CimInstance ConvertToDaily(ScheduledJobTrigger trigger, CimSession cimSession)
        {
            CimClass    cimClass    = cimSession.GetClass(CIM_TRIGGER_NAMESPACE, "MSFT_TaskDailyTrigger");
            CimInstance cimInstance = new CimInstance(cimClass);

            cimInstance.CimInstanceProperties["RandomDelay"].Value  = ScheduledJobWTS.ConvertTimeSpanToWTSString(trigger.RandomDelay);
            cimInstance.CimInstanceProperties["DaysInterval"].Value = trigger.Interval;

            AddCommonProperties(trigger, cimInstance);
            return(cimInstance);
        }
        private CimInstance ConvertToWeekly(ScheduledJobTrigger trigger, CimSession cimSession)
        {
            CimClass    @class      = cimSession.GetClass(JobTriggerToCimInstanceConverter.CIM_TRIGGER_NAMESPACE, "MSFT_TaskWeeklyTrigger");
            CimInstance cimInstance = new CimInstance(@class);

            cimInstance.CimInstanceProperties["DaysOfWeek"].Value    = ScheduledJobWTS.ConvertDaysOfWeekToMask(trigger.DaysOfWeek);
            cimInstance.CimInstanceProperties["RandomDelay"].Value   = ScheduledJobWTS.ConvertTimeSpanToWTSString(trigger.RandomDelay);
            cimInstance.CimInstanceProperties["WeeksInterval"].Value = trigger.Interval;
            JobTriggerToCimInstanceConverter.AddCommonProperties(trigger, cimInstance);
            return(cimInstance);
        }
示例#6
0
        private CimInstance ConvertToAtLogon(ScheduledJobTrigger trigger, CimSession cimSession)
        {
            CimClass    cimClass    = cimSession.GetClass(CIM_TRIGGER_NAMESPACE, "MSFT_TaskLogonTrigger");
            CimInstance cimInstance = new CimInstance(cimClass);

            cimInstance.CimInstanceProperties["Delay"].Value = ScheduledJobWTS.ConvertTimeSpanToWTSString(trigger.RandomDelay);

            // Convert the "AllUsers" name ("*" character) to null for Task Scheduler.
            string userId = (ScheduledJobTrigger.IsAllUsers(trigger.User)) ? null : trigger.User;

            cimInstance.CimInstanceProperties["UserId"].Value = userId;

            AddCommonProperties(trigger, cimInstance);
            return(cimInstance);
        }
        private CimInstance ConvertToOnce(ScheduledJobTrigger trigger, CimSession cimSession)
        {
            bool        valueOrDefault;
            CimClass    @class      = cimSession.GetClass(JobTriggerToCimInstanceConverter.CIM_TRIGGER_NAMESPACE, "MSFT_TaskTimeTrigger");
            CimInstance cimInstance = new CimInstance(@class);

            cimInstance.CimInstanceProperties["RandomDelay"].Value = ScheduledJobWTS.ConvertTimeSpanToWTSString(trigger.RandomDelay);
            TimeSpan?repetitionInterval = trigger.RepetitionInterval;

            if (repetitionInterval.HasValue)
            {
                TimeSpan?repetitionDuration = trigger.RepetitionDuration;
                if (repetitionDuration.HasValue)
                {
                    CimClass    cimClass  = cimSession.GetClass(JobTriggerToCimInstanceConverter.CIM_TRIGGER_NAMESPACE, "MSFT_TaskRepetitionPattern");
                    CimInstance wTSString = new CimInstance(cimClass);
                    TimeSpan?   nullable  = trigger.RepetitionInterval;
                    wTSString.CimInstanceProperties["Interval"].Value = ScheduledJobWTS.ConvertTimeSpanToWTSString(nullable.Value);
                    TimeSpan?repetitionDuration1 = trigger.RepetitionDuration;
                    TimeSpan maxValue            = TimeSpan.MaxValue;
                    if (!repetitionDuration1.HasValue)
                    {
                        valueOrDefault = false;
                    }
                    else
                    {
                        valueOrDefault = repetitionDuration1.GetValueOrDefault() == maxValue;
                    }
                    if (!valueOrDefault)
                    {
                        wTSString.CimInstanceProperties["StopAtDurationEnd"].Value = true;
                        TimeSpan?nullable1 = trigger.RepetitionDuration;
                        wTSString.CimInstanceProperties["Duration"].Value = ScheduledJobWTS.ConvertTimeSpanToWTSString(nullable1.Value);
                    }
                    else
                    {
                        wTSString.CimInstanceProperties["StopAtDurationEnd"].Value = false;
                    }
                    cimInstance.CimInstanceProperties["Repetition"].Value = wTSString;
                }
            }
            JobTriggerToCimInstanceConverter.AddCommonProperties(trigger, cimInstance);
            return(cimInstance);
        }
        private CimInstance ConvertToAtLogon(ScheduledJobTrigger trigger, CimSession cimSession)
        {
            string      user;
            CimClass    @class      = cimSession.GetClass(JobTriggerToCimInstanceConverter.CIM_TRIGGER_NAMESPACE, "MSFT_TaskLogonTrigger");
            CimInstance cimInstance = new CimInstance(@class);

            cimInstance.CimInstanceProperties["Delay"].Value = ScheduledJobWTS.ConvertTimeSpanToWTSString(trigger.RandomDelay);
            if (ScheduledJobTrigger.IsAllUsers(trigger.User))
            {
                user = null;
            }
            else
            {
                user = trigger.User;
            }
            string str = user;

            cimInstance.CimInstanceProperties["UserId"].Value = str;
            JobTriggerToCimInstanceConverter.AddCommonProperties(trigger, cimInstance);
            return(cimInstance);
        }
示例#9
0
        private void AddTaskTrigger(ITaskDefinition iTaskDefinition, ScheduledJobTrigger jobTrigger)
        {
            ITrigger         str;
            string           user;
            TriggerFrequency frequency = jobTrigger.Frequency;

            switch (frequency)
            {
            case TriggerFrequency.Once:
            {
                str = iTaskDefinition.Triggers.Create(_TASK_TRIGGER_TYPE2.TASK_TRIGGER_TIME);
                ITimeTrigger wTSString = str as ITimeTrigger;
                wTSString.RandomDelay = ScheduledJobWTS.ConvertTimeSpanToWTSString(jobTrigger.RandomDelay);
                TimeSpan?repetitionInterval = jobTrigger.RepetitionInterval;
                if (repetitionInterval.HasValue)
                {
                    TimeSpan?repetitionDuration = jobTrigger.RepetitionDuration;
                    if (repetitionDuration.HasValue)
                    {
                        TimeSpan?nullable = jobTrigger.RepetitionInterval;
                        wTSString.Repetition.Interval = ScheduledJobWTS.ConvertTimeSpanToWTSString(nullable.Value);
                        TimeSpan?repetitionDuration1 = jobTrigger.RepetitionDuration;
                        if (repetitionDuration1.Value != TimeSpan.MaxValue)
                        {
                            wTSString.Repetition.StopAtDurationEnd = true;
                            TimeSpan?nullable1 = jobTrigger.RepetitionDuration;
                            wTSString.Repetition.Duration = ScheduledJobWTS.ConvertTimeSpanToWTSString(nullable1.Value);
                        }
                        else
                        {
                            wTSString.Repetition.StopAtDurationEnd = false;
                        }
                    }
                }
                str.StartBoundary = ScheduledJobWTS.ConvertDateTimeToString(jobTrigger.At);
                int id = jobTrigger.Id;
                str.Id      = id.ToString(CultureInfo.InvariantCulture);
                str.Enabled = jobTrigger.Enabled;
                return;
            }

            case TriggerFrequency.Daily:
            {
                str = iTaskDefinition.Triggers.Create(_TASK_TRIGGER_TYPE2.TASK_TRIGGER_DAILY);
                IDailyTrigger interval = str as IDailyTrigger;
                interval.RandomDelay  = ScheduledJobWTS.ConvertTimeSpanToWTSString(jobTrigger.RandomDelay);
                interval.DaysInterval = (short)jobTrigger.Interval;
                str.StartBoundary     = ScheduledJobWTS.ConvertDateTimeToString(jobTrigger.At);
                int num = jobTrigger.Id;
                str.Id      = num.ToString(CultureInfo.InvariantCulture);
                str.Enabled = jobTrigger.Enabled;
                return;
            }

            case TriggerFrequency.Weekly:
            {
                str = iTaskDefinition.Triggers.Create(_TASK_TRIGGER_TYPE2.TASK_TRIGGER_WEEKLY);
                IWeeklyTrigger mask = str as IWeeklyTrigger;
                mask.RandomDelay   = ScheduledJobWTS.ConvertTimeSpanToWTSString(jobTrigger.RandomDelay);
                mask.WeeksInterval = (short)jobTrigger.Interval;
                mask.DaysOfWeek    = ScheduledJobWTS.ConvertDaysOfWeekToMask(jobTrigger.DaysOfWeek);
                str.StartBoundary  = ScheduledJobWTS.ConvertDateTimeToString(jobTrigger.At);
                int id1 = jobTrigger.Id;
                str.Id      = id1.ToString(CultureInfo.InvariantCulture);
                str.Enabled = jobTrigger.Enabled;
                return;
            }

            case TriggerFrequency.AtLogon:
            {
                str = iTaskDefinition.Triggers.Create(_TASK_TRIGGER_TYPE2.TASK_TRIGGER_LOGON);
                ILogonTrigger variable  = str as ILogonTrigger;
                ILogonTrigger variable1 = variable;
                if (ScheduledJobTrigger.IsAllUsers(jobTrigger.User))
                {
                    user = null;
                }
                else
                {
                    user = jobTrigger.User;
                }
                variable1.UserId = user;
                variable.Delay   = ScheduledJobWTS.ConvertTimeSpanToWTSString(jobTrigger.RandomDelay);
                int num1 = jobTrigger.Id;
                str.Id      = num1.ToString(CultureInfo.InvariantCulture);
                str.Enabled = jobTrigger.Enabled;
                return;
            }

            case TriggerFrequency.AtStartup:
            {
                str = iTaskDefinition.Triggers.Create(_TASK_TRIGGER_TYPE2.TASK_TRIGGER_BOOT);
                IBootTrigger wTSString1 = str as IBootTrigger;
                wTSString1.Delay = ScheduledJobWTS.ConvertTimeSpanToWTSString(jobTrigger.RandomDelay);
                int id2 = jobTrigger.Id;
                str.Id      = id2.ToString(CultureInfo.InvariantCulture);
                str.Enabled = jobTrigger.Enabled;
                return;
            }

            default:
            {
                return;
            }
            }
        }