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

NT AUTHORITY\SYSTEM

Aug 14, 2011 at 5:11 AM

I have seen a similar discussion but it didn't appear to have had a conclusion, would anyone know how to regsister the task as the SYSTEM account....

I seem to have tried every allowable combination and each throws and exception ---  Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))

Here is my code.

I'm working on Win 7 x64 box.

ts.RootFolder.RegisterTaskDefinition(@"IQ2Download1", td, TaskCreation.Create, @"NT AUTHORITY\SYSTEM", null, TaskLogonType.ServiceAccount, null);

Coordinator
Aug 14, 2011 at 11:37 PM

See this post for the syntax: http://taskscheduler.codeplex.com/discussions/256611

Aug 15, 2011 at 12:48 AM

Thanks unfortunately... I did read that one. I

my code is now identical to the example, (*I think*)

Here's the whole thing ---

 using (TaskService ts = new TaskService())
            {
                TaskDefinition td = ts.NewTask();

                td.Actions.Add(new ExecAction("notepad.exe", AppDomain.CurrentDomain.BaseDirectory, null));

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

 

But no matter what.....I still recieve the error below....

I'm hoping its just some boneheaded mistake I've made....

Again, any help would be greatly appreciated ----pulling out my last hair..

 

{"Access is denied.(Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))"}

   at Microsoft.Win32.TaskScheduler.V2Interop.ITaskFolder.RegisterTaskDefinition(String Path, ITaskDefinition pDefinition, Int32 flags, Object UserId, Object password, TaskLogonType LogonType, Object sddl)
   at Microsoft.Win32.TaskScheduler.TaskFolder.RegisterTaskDefinition(String Path, TaskDefinition definition, TaskCreation createType, String UserId, String password, TaskLogonType LogonType, String sddl)
   at WindowsFormsApplication1.Form1.button1_Click(Object sender, EventArgs e) in N:\WindowsFormsApplication1a\WindowsFormsApplication1a\Form1.cs:line 55
   at System.Windows.Forms.Control.OnClick(EventArgs e)
   at System.Windows.Forms.Button.OnClick(EventArgs e)
   at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
   at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ButtonBase.WndProc(Message& m)
   at System.Windows.Forms.Button.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
   at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
   at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
   at System.Windows.Forms.Application.Run(Form mainForm)
   at WindowsFormsApplication1.Program.Main() in N:\WindowsFormsApplication1a\WindowsFormsApplication1a\Program.cs:line 18
   at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
   at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
   at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
   at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ThreadHelper.ThreadStart()

Coordinator
Aug 15, 2011 at 2:12 PM

You must add a trigger before registering the task. A valid task must have both a trigger and an action.