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

Exception when using NETWORK SERVICE on Windows Server 2003

Jan 7, 2011 at 4:02 PM

Here is a fragment of my code:

taskDefinition.Principal.UserId = "NETWORK SERVICE";
taskDefinition.Principal.LogonType = TaskLogonType.ServiceAccount;


taskScheduler.RootFolder.RegisterTaskDefinition(taskDefinition.RegistrationInfo.Description, taskDefinition);

Here is the exception I receive:

Error: System.Runtime.InteropServices.COMException (0x80041314): The task has been configured with an unsupported combination of account settings and run time options. (Exception from HRESULT: 0x80041314)

Any thoughts?

Thanks, and great wrapper!!!

at System.Runtime.InteropServices.ComTypes.IPersistFile.Save(String pszFileName, Boolean fRemember)

Jan 7, 2011 at 11:45 PM
Edited Jan 7, 2011 at 11:47 PM

Running a task under a group account is only supported on Vista or Server 2008 and higher.

Jan 10, 2011 at 2:00 PM

Cool, thanks!

Mar 26, 2014 at 10:17 PM
Hi I am having the same issue.
OS = Win8 and Win Server 2008 R2.
I tried below code

td.Principal.LogonType = TaskLogonType.S4U;

also tried the code above.
But I get access denied error.

How can I create a task which can run as "NETWORK SERVICE" and "user logged in or not"

Apr 3, 2014 at 7:06 PM
Try the following:
td.Principal.UserId = "NETWORK SERVICE"; 
td.Principal.LogonType = TaskLogonType.ServiceAccount; 
Apr 16, 2014 at 12:43 AM
Thanks dahall for your response. Appreciate it.
After posting this doubt I was able to figure out a solution. I am pasting the same line of code I am using here so that anyone can use if required.
        td.Principal.Id = "any string";
        td.Principal.GroupId = "NETWORK SERVICE";
        td.Principal.RunLevel = TaskRunLevel.LUA;
        td.Principal.LogonType = TaskLogonType.S4U;
Following things are applicable in my case

1) I run my application (the scheduler which schedule job using library ) under IIS. It is basically a a web service which can be used to schedule task in windows.
2) IIS app pool runs as NETWORK SERVICE
3) Task run even if no one is logged in into the machine
4) Web service is running on the same machine where task are created
5) Task uses only local resources when they run

All the above features are working and tested. It is on production.
Marked as answer by dahall on 4/23/2014 at 8:56 PM