This project has moved and is read-only. For the latest updates, please go here.

Unable to register task which will run even if user is not logged in

Feb 11, 2010 at 3:30 PM
Edited Feb 12, 2010 at 5:10 AM


I'm trying to create a task with 'RunOnlyIfLoggedOn' property set to False.

But while setting this property, it is throwing me an exception as "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."


I'm using following code-


Dim taskDefinition As TaskDefinition = taskService.NewTask()

        taskDefinition.Data = ""

        taskDefinition.Principal.UserId = String.Concat(Environment.UserDomainName, "\", Environment.UserName)

        taskDefinition.Principal.LogonType = TaskLogonType.InteractiveToken

        taskDefinition.RegistrationInfo.Author = "Pavan"

        taskDefinition.RegistrationInfo.Description = ""

        taskDefinition.Settings.RunOnlyIfLoggedOn = False


For the last statement it throws "NotV2SupportedException" exception...

Can you please help me to solve this problem?

Thank you.




Feb 13, 2010 at 6:37 AM

The error text has your answer, the RunOnlyIfLoggedOn property is not supported when running on systems Vista and later (2.0). By setting the LogonType to InteractiveToken, you automatically imply that the task can only run when a user is interacting with the system which is only possible if they are logged on. It sounds like you may want to try setting the LogonType to InteractiveTokenOrPassword and supplying the password through the RegisterTaskDefinition method.

Feb 23, 2010 at 7:54 AM

Thanks bro. That's what I was trying to do.

One more problem is there, I'm not able to set End Date of a Task in XP.

I'm settings it through EndBoundary property of the task, and its working fine in VISTA or Windows 7. In XP it is not giving any exception, but not even setting it.

I'm not getting why this is happening.


Feb 23, 2010 at 3:01 PM

Microsoft's Task Scheduler 1.0 COM library (pre-Vista) only supports setting the date of an EndBoundary. The time information is discarded. I will add this note to the help file.

Feb 25, 2010 at 2:26 PM

I'm so sorry, but even if I set only date of an EndBoundary then also its not working in XP.

Following is my code

 runOnceTrigger.StartBoundary = New DateTime(Me.StartDate.Year, Me.StartDate.Month, Me.StartDate.Day, Me.StartTimeHours, Me.StartTimeMinutes, 0)

         runOnceTrigger.EndBoundary = New Date(Me.StopDate.Year, Me.StopDate.Month, Me.StopDate.Day)


the End Date field of the task remains unchecked...

Feb 25, 2010 at 5:18 PM

Is your code or the assembly from before January 12, 2010? If so, there was a bug in the code for EndBoundary.

Mar 13, 2010 at 5:17 AM


I'm able to create a task which will run even if user is not logged in, but there is one more problem with this option which is coming for XP.

If there is a task with 'Run only if logged on' option checked, then I'm not able to edit that task to uncheck this option.

I'm passing LogonType as InteractiveTokenOrPassword and valid User name and Password too. It is not not throwing any exception but it is not modifying that task also!  

Mar 13, 2010 at 6:53 AM

Hey, I got solution for this problem.

Previously I was using TaskDefinition of the existing task, now I'm creating new TaskDefinition for that task and passing it to RegisterTaskDifinition method.

As I'm passing TaskCreation flag as CreateOrUpdate, it just updates the existing task from Windows Task Scheduler.

Mar 15, 2010 at 7:24 AM

Hi! Can anyone please tell me, how could I use "Do not store password" option through this DLL?

Mar 16, 2010 at 8:15 PM

This is done by registering the task using the LogonType.S4U value. From a great article on Task Scheduler 2.0 the author describes S4U as an "option that provides a more secure alternative [to providing a password]. It takes advantage of a service for user (S4U) logon to run the task on behalf of the specified user, but without having to store the password. Since the Task Scheduler runs within the local system account, it can create a S4U logon session and receive a token that can not only be used for identification, but also for impersonation on the local computer. Normally a S4U token is only good for identification."

For example:

ts.RootFolder.RegisterTaskDefinition(taskName, td, TaskCreation.Create, @"DOMAIN\user", null, TaskLogonType.S4U, null);
Jan 10, 2012 at 9:55 PM

I have a WCF service running under local system, I am able to create a task, but I can not run it due to security issues. I don't want to specify a domain user to run the task, is it possible to create a task and run the task as local system? when trying to specify Domain\machineName$ as the user I get access denied error.

Jan 11, 2012 at 3:15 AM

Yes. You just need to specify the SYSTEM account when you register the task.

ts.RootFolder.RegisterTaskDefinition("TEST", td, TaskCreation.CreateOrUpdate, "SYSTEM", null, TaskLogonType.ServiceAccount);
Jan 11, 2012 at 2:09 PM
dahall wrote:

Yes. You just need to specify the SYSTEM account when you register the task.

ts.RootFolder.RegisterTaskDefinition("TEST", td, TaskCreation.CreateOrUpdate, "SYSTEM", null, TaskLogonType.ServiceAccount);

Thank you. I have tried it, but any program I try to run I get an error message: 

Task Scheduler failed to start "\Test" task for user "NT AUTHORITY\System". Additional Data: Error Value: 2147750687. do I need something special to run applications under that account? I need to launch a .NET application (no UI) that will simply ping a service for me... 


Jan 11, 2012 at 9:37 PM

The System account likely does not have the rights to use networking. You will need to specify an account that has the rights on the local machine to run all the aspects of whatever the task needs to execute.

Jan 12, 2012 at 4:38 PM

got it working, there was some UI going on after all, when I took it out it worked...

you guys did a great job on this wrapper, I need to use for 2003 too, I hope it will be fine... Thanks for all the support!!!