-
I have a WPF application that I am attempting to start upon every logon of a user. The only issue is that the specified group is "SYSTEM" since I am creating the task from a service application. So, when the application is started, the UI will never appear (as expected). If I go into the Task Scheduler UI and manually change the user/group to "Users", the WPF application opens and the UI is visible. This is the current script: // Create a new task definition for the local machine and assign properties
TaskDefinition td = TaskService.Instance.NewTask();
td.RegistrationInfo.Description = "Launch test-login";
//td.Settings.RunOnlyIfLoggedOn = true;
#pragma warning disable CA1416 // Validate platform compatibility
string userId = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
#pragma warning restore CA1416 // Validate platform compatibility
td.Principal.UserId = userId;
td.Principal.LogonType = TaskLogonType.InteractiveToken;
LogonTrigger lt = new LogonTrigger();
td.Triggers.Add(lt);
string executePath = Path.GetDirectoryName(Environment.GetCommandLineArgs()[0]) + "\\login.exe";
td.Actions.Add(executePath);
// Register the task in the root folder of the local machine
TaskService.Instance.RootFolder.RegisterTaskDefinition("login-start", td, TaskCreation.CreateOrUpdate, userId, logonType: TaskLogonType.InteractiveToken); I understand why the above code won't work, since |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
You're on the right track. Do not set the TaskService.Instance.RootFolder.RegisterTaskDefinition("westlightlogin-start", td, TaskCreation.CreateOrUpdate, "YourDomain\\GroupAcct", null, TaskLogonType.Group); |
Beta Was this translation helpful? Give feedback.
-
Removing the // Register the task in the root folder of the local machine
TaskService.Instance.RootFolder.RegisterTaskDefinition("login-start", td, TaskCreation.CreateOrUpdate, "Authenticated Users", null, TaskLogonType.Group); |
Beta Was this translation helpful? Give feedback.
You're on the right track. Do not set the
td.Principal
properties. Then, in theRegisterTaskDefinition
call, do the following: