dahall / TaskScheduler

Provides a .NET wrapper for the Windows Task Scheduler. It aggregates the multiple versions, provides an editor and allows for localization.
MIT License
1.21k stars 191 forks source link

Task registred on Windows Server #841

Closed Torchok19081986 closed 4 years ago

Torchok19081986 commented 4 years ago

Hallo, can you help me . I have a problem with Task registred on Windows Server with Domain\User. I have to register new Task with Domain\Administrator. After i Task was sucecssfully created, Taskuser shows only Administrator, but domainname are missing. For currentdomain i use Enviroment.UserDomainName systemvariable and User is constant Administrator. Current code looks following:

 TaskDefinition td = TaskService.Instance.NewTask();
                td.RegistrationInfo.Description = "Packages";          
                DailyTrigger dt = td.Triggers.Add(new DailyTrigger(1));            
                td.Settings.DisallowStartIfOnBatteries = true;
                td.Settings.Enabled = false;
                td.Settings.ExecutionTimeLimit = TimeSpan.FromHours(2);
                td.Settings.Hidden = false;           
                td.Settings.IdleSettings.RestartOnIdle = false;
                td.Settings.IdleSettings.StopOnIdleEnd = false;      
                td.Settings.Priority = System.Diagnostics.ProcessPriorityClass.Normal;
                td.Settings.RunOnlyIfIdle = false;
                td.Settings.RunOnlyIfNetworkAvailable = false;
                td.Settings.StopIfGoingOnBatteries = false;
                td.Principal.RunLevel = TaskRunLevel.Highest;
                td.Settings.AllowDemandStart = true;
                td.Settings.AllowHardTerminate = true;
                td.Settings.Compatibility = TaskCompatibility.V2;
                td.Settings.MultipleInstances = TaskInstancesPolicy.StopExisting;
                td.Settings.StartWhenAvailable = true;
                td.Settings.WakeToRun = false;
                td.Settings.RunOnlyIfLoggedOn = false;             
                td.Actions.Add(new ExecAction(exepath, args, workingdir));
                // Register the task in the root folder
                const string taskName = "Serverupdater";             
                TaskService.Instance.RootFolder.RegisterTaskDefinition(taskName, td, TaskCreation.CreateOrUpdate, windowsuser, windowsuserpwd, TaskLogonType.Password); //windowsuser should be Domain\Administrator. 

do i something wrong or why Domain is missing ?

dahall commented 4 years ago

If you are saying that after registration, the UI only displays "Administrator", then all is fine. The UI drops the current domain from well known SIDS and system accounts. If you export the task, you should see the full name in the XML.

dahall commented 4 years ago

Closing due to inactivity. Please reopen if you still need assistance.