Esempio n. 1
0
        internal ScheduledTaskEntry(IRegisteredTask task)
        {
            SecurityDescriptor = SecurityDescriptor.Parse(task.GetSecurityDescriptor((int)SecurityInformation.AllBasic), false).GetResultOrDefault();
            Path    = task.Path;
            Enabled = task.Enabled;
            Xml     = task.Xml;
            var definition = task.Definition;
            var settings   = definition.Settings;

            Hidden           = settings.Hidden;
            AllowDemandStart = settings.AllowDemandStart;
            var principal = definition.Principal;

            if (principal.RunLevel == _TASK_RUNLEVEL.TASK_RUNLEVEL_HIGHEST)
            {
                RunLevel = TaskRunLevel.Highest;
            }

            List <string> privs = new List <string>();

            if (principal is IPrincipal2 prin2)
            {
                privs.AddRange(Enumerable.Range(0, prin2.RequiredPrivilegeCount).Select(i => prin2.RequiredPrivilege[i]));
                ProcessTokenSid = (TaskProcessTokenSid)(int)prin2.ProcessTokenSidType;
            }
            RequiredPrivilege = privs.AsReadOnly();

            TaskLogonType logon_type     = TaskLogonType.None;
            string        principal_name = string.Empty;

            switch (principal.LogonType)
            {
            case _TASK_LOGON_TYPE.TASK_LOGON_GROUP:
                logon_type     = TaskLogonType.Group;
                principal_name = principal.GroupId;
                break;

            case _TASK_LOGON_TYPE.TASK_LOGON_INTERACTIVE_TOKEN:
            case _TASK_LOGON_TYPE.TASK_LOGON_PASSWORD:
            case _TASK_LOGON_TYPE.TASK_LOGON_INTERACTIVE_TOKEN_OR_PASSWORD:
                logon_type     = TaskLogonType.User;
                principal_name = principal.UserId;
                break;

            case _TASK_LOGON_TYPE.TASK_LOGON_SERVICE_ACCOUNT:
                logon_type     = TaskLogonType.ServiceAccount;
                principal_name = principal.UserId;
                break;

            case _TASK_LOGON_TYPE.TASK_LOGON_S4U:
                logon_type     = TaskLogonType.S4U;
                principal_name = principal.UserId;
                break;
            }
            LogonType          = logon_type;
            Principal          = principal_name;
            Actions            = definition.Actions.Cast <IAction>().Select(a => new ScheduledTaskAction(a)).ToList().AsReadOnly();
            HasActionArguments = Actions.Any(a => a.HasArguments);
            Triggers           = definition.Triggers.Cast <ITrigger>().Select(ScheduledTaskTrigger.Create).ToList().AsReadOnly();
        }
Esempio n. 2
0
 public string GetSecurityDescriptorSddlForm(AccessControlSections includeSections)
 {
     if (_v2Task == null)
     {
         throw new NotV1SupportedException();
     }
     return(_v2Task.GetSecurityDescriptor((int)includeSections));
 }
            public TaskSchedulerEntry(IRegisteredTask task)
            {
                SecurityDescriptor = task.GetSecurityDescriptor((int)SecurityInformation.AllBasic);
                Path    = task.Path;
                Enabled = task.Enabled;
                Xml     = task.Xml;
                var definition = task.Definition;
                var settings   = definition.Settings;

                Hidden           = settings.Hidden;
                AllowDemandStart = settings.AllowDemandStart;
                var principal = definition.Principal;

                if (principal.RunLevel == _TASK_RUNLEVEL.TASK_RUNLEVEL_HIGHEST)
                {
                    RunLevel = TaskRunLevel.Highest;
                }

                TaskLogonType logon_type     = TaskLogonType.None;
                string        principal_name = string.Empty;

                switch (principal.LogonType)
                {
                case _TASK_LOGON_TYPE.TASK_LOGON_GROUP:
                    logon_type     = TaskLogonType.Group;
                    principal_name = principal.GroupId;
                    break;

                case _TASK_LOGON_TYPE.TASK_LOGON_INTERACTIVE_TOKEN:
                case _TASK_LOGON_TYPE.TASK_LOGON_PASSWORD:
                case _TASK_LOGON_TYPE.TASK_LOGON_INTERACTIVE_TOKEN_OR_PASSWORD:
                    logon_type     = TaskLogonType.User;
                    principal_name = principal.UserId;
                    break;

                case _TASK_LOGON_TYPE.TASK_LOGON_SERVICE_ACCOUNT:
                    logon_type     = TaskLogonType.ServiceAccount;
                    principal_name = principal.UserId;
                    break;

                case _TASK_LOGON_TYPE.TASK_LOGON_S4U:
                    logon_type     = TaskLogonType.S4U;
                    principal_name = principal.UserId;
                    break;
                }
                LogonType = logon_type;
                Principal = principal_name;
                Actions   = definition.Actions.Cast <IAction>().Select(a => new ScheduledTaskAction(a)).ToList().AsReadOnly();
            }