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

Show task while running as SYSTEM account #896

Closed yingying96 closed 3 years ago

yingying96 commented 3 years ago

Hi,

Would like to check how do I run as SYSTEM account while keeping the config of "Run only when the user is logged on"? I realized that only when i select "Run only when the user is logged on", then the GUI of the exe that i am running appears.

Here's a sample of my code.

        static void ScheduleTask(String TaskName, String Date)
        {
            using (TaskService ts = new TaskService())
            {
                TaskDefinition td = ts.NewTask();
                td.RegistrationInfo.Description = TaskName;
                td.Triggers.Add(new TimeTrigger() { StartBoundary = Convert.ToDateTime(Date) });

                td.Actions.Add(new ExecAction(@"%windir%\notepad.exe", null, null));
                // ts.RootFolder.RegisterTaskDefinition(TaskName, td);
                ts.RootFolder.RegisterTaskDefinition(TaskName, td, TaskCreation.CreateOrUpdate, "SYSTEM", null, TaskLogonType.ServiceAccount);
            }
        }
dahall commented 3 years ago

Those two settings, running as SYSTEM and running when logged in, are mutually exclusive. What you want to do cannot be done.

yingying96 commented 3 years ago

I see! Then is there a way to run as SYSTEM account but have the GUI of the exe from the task running to show?

dahall commented 3 years ago

There is not

yingying96 commented 3 years ago

Ok thanks!