We are currently using TaskService
to schedule a task. We use the default folder:
TaskScheduler scheduler = new TaskScheduler();
scheduler.Connect();
ITaskFolder rootFolder = scheduler.GetFolder("");
which turns out to be:
C:\\Windows\\System32\\Tasks
This works great for admin users, but now I'm trying to schedule a task for non-admin users. Now the above code throws a UnauthorizedAccessException
.
I've tried specifying a user specific file paths:
"\\Users\\some_user" // FileNotFoundException: The system cannot find the file specified
"C:\\Users\\some_user" // FileNotFoundException: The filename, directory name, or volume label syntax is incorrect
Any ideas?
I'm not sure how scheduler.GetFolder("")
was throwing an UnauthorizedAccessException
, it seems to work fine now.
What I ended up doing was something like:
TaskScheduler scheduler = new TaskScheduler();
scheduler.Connect();
ITaskFolder rootFolder = scheduler.GetFolder(string.Empty);
ITaskFolder userSpecificFolder = rootFolder.CreateFolder(scheduler.ConnectedUser); // Will throw if folder already exists
// Now can add tasks to userSpecificFolder
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.