我以编程方式创建 TaskScheduler 的任务并运行它。我正在使用以下代码:
var taskDefinition = taskService.NewTask();
taskDefinition.RegistrationInfo.Author = WindowsIdentity.GetCurrent().Name;
taskDefinition.RegistrationInfo.Description = "Runs Programm";
// TaskLogonType.S4U = run wether user is logged on or not
taskDefinition.Principal.LogonType = TaskLogonType.S4U;
var action = new ExecAction(path, arguments);
taskDefinition.Actions.Add(action);
taskService.RootFolder.RegisterTaskDefinition("TaskName", taskDefinition);
//get task:
var task = taskService.RootFolder.GetTasks().Where(a => a.Name == "TaskName").FirstOrDefault();
try
{
task.Run();
}
catch (Exception ex)
{
log.Error("Error starting task in TaskSheduler with message: " + ex.Message);
}
任务已创建,我可以在 TaskScheduler 窗口中看到它,但我希望取消选中一个复选框。它被称为“不存储密码。任务将只能访问本地资源”
我发现了如何检查上面的单选按钮,上面写着“无论用户是否登录都运行”这是通过以下方式设置的:
taskDefinition.Principal.LogonType = TaskLogonType.S4U;
但是我如何也将下面的复选框设置为 false?