我想在根文件夹中创建一个计划任务。这是我的代码
using (TaskService ts = new TaskService())
{
TaskDefinition td = ts.NewTask();
td.RegistrationInfo.Description = "notepad";
td.Principal.UserId = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
td.Principal.LogonType = TaskLogonType.InteractiveToken;
td.Triggers.Add(new LogonTrigger() { Enabled = true });
td.Principal.RunLevel = TaskRunLevel.Highest;
td.Settings.DisallowStartIfOnBatteries = false;
td.Settings.StopIfGoingOnBatteries = false;
td.Settings.ExecutionTimeLimit = TimeSpan.Zero;
td.Actions.Add(new ExecAction("notepad.exe", null, null));
// Register the task in the root folder
ts.RootFolder.RegisterTaskDefinition(@"Browser", td);
}
即使我的用户是管理员,该应用程序也会拒绝访问#34;
其他信息:访问被拒绝。 (HRESULT异常:0x80070005(E_ACCESSDENIED))