This project has moved. For the latest updates, please go here.

Task Scheduler 2.0 settings - Bug Found?

Topics: Errors
May 2 at 5:36 PM
Edited May 2 at 5:36 PM
Hello,

I am working on using the TSMW setting up some tasks that use the 'run only if logged on' Task Scheduler 2.0 feature, and I have been running into problems.

I keep getting errors to the effect of 'Task Scheduler 2.0 (1.2) does not support setting this property. You must use an InteractiveToken in order to have the task run in the current user session.' The problem though is that I think I am setting a token correctly.

I dug into the source code (taskscheduler-98194) and I found that the error message is generated when the code attempts to set the Tasks.RunOnlyIfLoggedOn property. It looks like the error is generated if the v2Settings are NOT null. I would think that this should check for null, but I don't know the code base or object's internal logic. I found it very difficult to get the code compiling because of all the 3rd party add ins, or I would have just fixed it myself.

My question is: Is this an error I have found? If it is not, what is the correct way to set an interactive logon token?

I have a full write up posted on Stack Overflow with code samples, if that helps:
http://stackoverflow.com/questions/43599271/how-to-set-run-only-if-logged-in-and-run-as-with-taskscheduler-in-c
Coordinator
May 3 at 2:58 AM
This is not an error as is indicated in multiple threads on this discussion board. (e.g. http://taskscheduler.codeplex.com/discussions/633848)

This was a setting provided for backwards compatibility with the V1 library where this setting works. Under V2, you must, as the exception states, use the InteractiveToken enum on the RegisterTaskDefinition instead of setting that property.
Marked as answer by dahall on 5/2/2017 at 6:58 PM
May 3 at 7:04 PM
Ahhhhh, that explains it. My problem is solved.

There are two places that you set the Interactive token: the TaskDefinition.Principal.LoginType and in the RegisterTaskDefinition call.

Might I recommend that the error message be slightly altered to reflect what you just said. As it stands now, the message tells you nothing helpful about what specifically needs to be done to correct the problem.

'Task Scheduler 2.0 (1.2) does not support setting this property. You must use an InteractiveToken in order to have the task run in the current user session.'

To something like:

'Task Scheduler 2.0 (1.2) does not support setting this property. You must specify using an InteractiveToken in the RegisterTaskDefinition in order to have the task run in the current user session.'

Thanks for the help, I will update my SO question to assist others.