TaskScheduler icon indicating copy to clipboard operation
TaskScheduler copied to clipboard

Task is not created if try with different user

Open YordanYanakiev opened this issue 2 years ago • 1 comments

Trying to run the scheduler from a system service, as the idea is to start an executable, yet by some reason it doesnt create a new task: The local username is "Sun", and the computer name is "Sun-PC"


                    using (TaskService ts = new TaskService())
                    {

                        TaskDefinition td = ts.NewTask();
                        td.RegistrationInfo.Description = "ObeserverGuard";
                        // Create an action that will launch Notepad whenever the trigger fires
                        td.Actions.Add(new ExecAction( "notepad.exe", "test.log", null ) );

                        ts.RootFolder.RegisterTaskDefinition( @"G:\Projects\Elx\Service\ObserverService\ObserverService\bin\Debug\", td, TaskCreation.CreateOrUpdate, "Sun", "", TaskLogonType.InteractiveToken );
                        ts.Execute( "notepad.exe" )
                            .Once()
                            .Starting( DateTime.Now.AddSeconds( 1 ) )
                            .AsTask( "ObeserverGuard" );
                    }

YordanYanakiev avatar May 18 '23 06:05 YordanYanakiev

See https://github.com/dahall/TaskScheduler/wiki/TaskSecurity

dahall avatar May 19 '23 03:05 dahall