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.2k stars 191 forks source link

Task is not created if try with different user #965

Closed YordanYanakiev closed 3 months ago

YordanYanakiev commented 1 year ago

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" );
                    }
dahall commented 1 year ago

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