Windows XP SP3 System Account.

Topics: Errors, Examples
Apr 29, 2014 at 12:46 PM
Hi,

I have a problem registering a task in windows XP SP3 and run it under system account.
The task is created but when i hit run nothing happens: no entry in log file and "LastRunTime" is Never.


Can anybody tell me what are the correct commands in order to achieve this ?
                using (TaskService ts = new TaskService())
                {
                    isVersionOne = ts.HighestSupportedVersion < new Version(1, 2);

                    TaskDefinition td = ts.NewTask();
                    td.RegistrationInfo.Description = "Task";
                    td.RegistrationInfo.Author = "Me";
                    td.Principal.UserId = @"System";
                    td.Principal.LogonType = TaskLogonType.ServiceAccount;
                    td.Settings.RunOnlyIfLoggedOn = true;
                    td.Triggers.Add(new DailyTrigger
                    {
                        StartBoundary = DateTime.Now,
                        DaysInterval = 2
                    });

                    td.Actions.Add(new ExecAction("\"" + @"C:\ConsoleApplication.exe" + "\""));
                    var task = ts.RootFolder.RegisterTaskDefinition("Test Task", td, TaskCreation.Create, null, null, TaskLogonType.ServiceAccount, null);
                }

Thank you !
Coordinator
Apr 29, 2014 at 3:54 PM
Edited Apr 29, 2014 at 9:41 PM
You cannot combine RunOnlyIfLoggedOn and service accounts. You also have a problem with V1 on how you are using Principal. You will get a more consistent result by putting all the account information for new tasks in the registration:
using (TaskService ts = new TaskService())
{
    TaskDefinition td = ts.NewTask();
    td.RegistrationInfo.Description = "Task";
    td.RegistrationInfo.Author = "Me";
    td.Triggers.Add(new DailyTrigger(2));
    td.Actions.Add(new ExecAction(@"C:\ConsoleApplication.exe"));
    var task = ts.RootFolder.RegisterTaskDefinition("Test Task", td,
        TaskCreation.CreateOrUpdate, "SYSTEM", null, TaskLogonType.ServiceAccount,
        null);
}
Apr 29, 2014 at 4:15 PM
Removing that line it generates the following error:

"Test Task.job" (ConsoleApplication.exe) 4/29/2014 6:12:41 PM ** ERROR **
The attempt to log on to the account associated with the task failed, therefore, the task did not run.
The specific error is:
0x80041314: The task has been configured with an unsupported combination of account settings and run time options.
Verify that the task's Run-as name and password are valid and try again.
I can't find any solution for this error.
Apr 29, 2014 at 4:30 PM
Edited Apr 29, 2014 at 4:31 PM
Same error running your sample:
"Test Task.job" (ConsoleApplication.exe) 4/29/2014 6:28:10 PM ** ERROR **
The attempt to log on to the account associated with the task failed, therefore, the task did not run.
The specific error is:
0x80041314: The task has been configured with an unsupported combination of account settings and run time options.
Verify that the task's Run-as name and password are valid and try again.
[ ***** Most recent entry is above this line ***** ]

I've tested on another XP SP3 machine and the same result.
Coordinator
Apr 29, 2014 at 9:37 PM
Will you try the sample just the way I posted it in my reply and let me know if you get the same error?
Apr 30, 2014 at 9:06 AM
I've tried the sample but still the same error:
"Test Task.job" (ConsoleApplication.exe) 4/30/2014 10:45:23 AM ** ERROR **
The attempt to log on to the account associated with the task failed, therefore, the task did not run.
The specific error is:
0x80041314: The task has been configured with an unsupported combination of account settings and run time options.
Verify that the task's Run-as name and password are valid and try again.
[ ***** Most recent entry is above this line ***** ]
Image

After some investigations I've realized that running the AT command the task will run under the local system account but the properties window is read only.

Image

Is there a way to achieve this using this library ? Maybe there is a XP setting that I don't know about it ?

Thank you again.
Apr 30, 2014 at 1:45 PM
Has this something to do with: https://support.microsoft.com/kb/223375 ?
Coordinator
Apr 30, 2014 at 6:59 PM
I have just run the following code on XP SP3 (as an Administrator) with complete success.
TaskDefinition td = ts.NewTask();
td.RegistrationInfo.Description = "Test for XP SP3";
td.RegistrationInfo.Author = "incaunu";
td.Triggers.Add(new DailyTrigger() { StartBoundary = new DateTime(2014, 1, 15, 9, 0, 0), EndBoundary = DateTime.Today.AddMonths(1) });
td.Actions.Add(new ExecAction("cmd.exe", "/c \"date /t > c:\\cmd.txt\""));
Task t = ts.RootFolder.RegisterTaskDefinition(taskName, td, TaskCreation.CreateOrUpdate, "SYSTEM", null, TaskLogonType.ServiceAccount);
May 5, 2014 at 1:03 PM
Edited May 13, 2014 at 4:28 PM
I solved my problem following these steps. Now your code works like a charm.
Marked as answer by dahall on 5/5/2014 at 12:44 PM
Jun 19, 2014 at 8:26 AM
I am trying to create task on Windows XP machine SP3, Using DLL version 2.2.0.18504.The above code creates schedule task on "NT AUTHORITY\System" . The Last Run Time is always Never whereas next run time changes as it should be. The action doesn't seem to run. When I right click on task and click Run, it says Could not start. Can you help me fix this?

Thanks
Mano
Jun 19, 2014 at 9:42 PM
incaunu,

I am experiencing the same issue as posted here.

Can you please help me to fix it? what did you do? the link you have for steps points to another error message.

Thanks in advance.
Mano