Click here to Skip to main content
15,355,659 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi sir,
When I was in the development of the client, need using taskschedule to unauthorized client user remind matters, but Microsoft in.NET was not related to library, and used the TaskScheduler.dll (ver1.3) and Microsoft.Win32.TaskScheduler.dll (ver2.0) two files, Microsoft.Win32.TaskScheduler.dll work very well in WIN7, the same code in the WinXP can not work. In the code to judge the current OS type is XP or WIN7 and then call the related classes to establish task, in using TaskScheduler.dll to build task was wrong (access denied. (an exception from HRESULT:0x80070005 (E_ACCESSDENIED))) and the task start is not successful, if the management interface check "run only after the login" can work normally start.

Q1: how to check the "run only" after the login in the code?
Q2: how to use Microsoft.Win32.TaskScheduler.dll compatible with WINXP?

Code:using Microsoft.Win32.TaskScheduler.dll(W7)
var ts = new TaskService();

var td = ts.NewTask();
td.RegistrationInfo.Description = "Alert Message To User Task";
td.RegistrationInfo.Author = "Deepres";
td.RegistrationInfo.URI = "";

Trigger dt = new DailyTrigger { DaysInterval = 1 };
dt.ExecutionTimeLimit = TimeSpan.FromHours(1);
dt.StartBoundary = DateTime.Now.AddMinutes(3);
dt.Repetition.Duration = TimeSpan.FromHours(24);
dt.Repetition.Interval = TimeSpan.FromMinutes(30);


var sPath = Common.StrDecode(Cah.ReadValue("NavAppUrl", "NavAUrl"));
var exe = new ExecAction(sPath);


ts.RootFolder.RegisterTaskDefinition(@"AlertMsgToUser", td);

Code:using TaskScheduler.dll(WXP)
to build without permission error.
var st = new ScheduledTasks();
var t = st.CreateTask(name);
var sPath = Common.StrDecode(Cah.ReadValue("NavAppUrl", "NavAUrl"));
t.ApplicationName = sPath;
t.Comment = "Alert a message to on logon user";

t.SetAccountInformation(Environment.UserName, "");

t.IdleWaitMinutes = 10;

t.Priority = System.Diagnostics.ProcessPriorityClass.Idle;

t.Triggers.Add(new DailyTrigger(14, 30));


This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900