Create a Task to Run as LocalSystem

Jan 23, 2009 at 2:08 AM
Edited Jan 23, 2009 at 2:23 AM
Has anyone been able to create a Task that runs as System (NT AUTHORITY\SYSTEM) in XP?  I can successfully create one under Vista, but under XP it either default to my current login, or gives me an HRESULT error that the task has been configured with an unsupported combination of account settings and runtime options.

One other note:  I want the task to run whether the user is logged in or not (e.g. TaskLoginType.ServiceAccount).  Perhaps that is not supported in XP, although it seems to be from the UI??
Jan 23, 2009 at 2:46 AM
OK - To answer my own question - I just needed to supply NULL as the account and password along with TaskLoginType.ServiceAccount to get my desired result.  I probably would have stumbled onto this via trial and error, but instead read up on the IScheduledWorkItem COM Interface on MSDN to find the solution. 

BTW - thanks - this library is a big time saver!
Feb 25, 2009 at 12:16 PM
Hi, how you got System (NT AUTHORITY\SYSTEM)  in Vista?
May 29, 2009 at 1:04 PM

Hi, I think I am having a similar problem.

I need to develop a scheduled task to work on XP and Vista and using Local System as account information.

It seems that everything goes OK (I am following but the Task Schedule 1.0 Examples from msdn) but the result of doing pIPersistFile->Save(NULL,TRUE) gives me an error 0x80041316  SCHED_E_UNEXPECTEDNODE  and I don't know  how to solve it.

I think the problem is in the pITask->SetAccountInformation(L"",NULL) I am using.

How can I solve the problem?

Thanks.

 


Coordinator
Jun 2, 2009 at 7:24 PM

This forum is for discussing the .NET wrapper around the COM interfaces for both the 1.0 and 2.0 Task Scheduler libraries and not a general support group for troubleshooting Task Scheduler coding problems. There are examples and threads in this forum that describe how to accomplish what you are doing using this wrapper library. Please feel free to post if you are having specific issues with this library.

Oct 27, 2009 at 5:03 AM

Hi bbalmer,

 

Could you please elaborate "I just needed to supply NULL as the account and password along with TaskLoginType.ServiceAccount to get my desired result." ? I am having the same issue but can't resolve it...

 

Thanks

Oct 27, 2009 at 2:16 PM

I believe something was changed or improved since I made this post - my current code using the newest version of the library looks like this.

 

currently I simply create the task like this (never supplying a password). 

 

td.Principal.LogonType = TaskLogonType.InteractiveToken;
td.Principal.UserId = "NT AUTHORITY\\SYSTEM";

 Later I register the task like this

ts.RootFolder.RegisterTaskDefinition(TaskName, td, TaskCreation.CreateOrUpdate, null, null, TaskLogonType.ServiceAccount, null);