1
Vote

Error registering task on Windows Vista

description

On Windows Vista, I can't register a task when a password is required. I'm using the version 2.5.27 of the wrapper.
The next code works on other operative systems, but not in Windows Vista:

TaskDefinition td = taskScheduler.NewTask();
td.Actions.Add(Application.ExecutablePath, string.Format("\"{0}\"", configPath));
td.Settings.DisallowStartIfOnBatteries = false;
td.Settings.StopIfGoingOnBatteries = false;

Task task = taskScheduler.RootFolder.RegisterTaskDefinition(taskName, td);
task.Definition.Principal.LogonType = TaskLogonType.Password;
task.Definition.Principal.RunLevel = TaskRunLevel.Highest;

TaskEditDialog editorForm = new TaskEditDialog(task, true, true);
editorForm.ShowDialog();

When clicking on OK button of the Task Edit Dialog, we are prompted to type password of the account. Even if the password is right, we get the error of the screenshot.

file attachments

comments

dahall wrote Jun 27 at 4:13 PM

Your problem is not in the code. I have tested it on Vista without error. Therefore, the problem must lie with permissions. Please see http://taskscheduler.codeplex.com/wikipage?title=TaskSecurity for information on appropriate permissions to edit a task. You may try using the TaskEditDialog constructor that takes a TaskDefinition instance and not pre-registering the task before calling the dialog.

wrote Jun 29 at 12:23 PM

Colecas wrote Jun 29 at 12:23 PM

I have added my account to the Administrator group. But the problem persists.
See the attachment, I'm using the account administrator of the domain.
I will try to use the TaskEditDialog constructor that takes a TaskDefinition.

Colecas wrote Jun 29 at 1:46 PM

Using the TaskEditDialog constructor that takes de TaskDefinition, I get the same error.

TaskDefinition td = taskScheduler.NewTask();
td.Actions.Add(Application.ExecutablePath, string.Format("\"{0}\"", configPath));
td.Settings.DisallowStartIfOnBatteries = false;
td.Settings.StopIfGoingOnBatteries = false;
td.Principal.RunLevel = TaskRunLevel.Highest;
td.Principal.LogonType = TaskLogonType.Password;

TaskEditDialog editorForm = new TaskEditDialog(taskScheduler, td, true, true);
editorForm.TaskName = taskName;
editorForm.ShowDialog();

dahall wrote Jul 1 at 4:32 PM

Please try running the troubleshooter @ https://taskscheduler.codeplex.com/releases/view/622295

mpthegr wrote Jul 1 at 5:16 PM

I still see the error.
I cannot tell customers to use the tool and resolve the problem.
Other windows applications(running under the same user) are able to create tasks in taskscheduler.

can you suggest some-other solution.

dahall wrote Jul 2 at 4:10 AM

My guess, given that other programs work, is that there is something tied to UAC for your program unique to that system. Have you tested this on multiple Windows 7 machines? If it is just this one, then check those permissions. If multiple, then check your program's manifest. I can tell you that multiple Windows 7 and Vista installations are working with the latest bits.

wrote Jul 12 at 3:10 PM

Colecas wrote Jul 12 at 3:10 PM

I still have this error in Windows Vista. Not reproduced in Windows 7 or later.
I have used your Test Task Scheduler, as you can see in the screenshot.

wrote Jul 12 at 3:23 PM

Colecas wrote Jul 12 at 3:23 PM

The error happens if we pass though the TaskEditDialog. But If we try to register the task directly, we don't get any error, as you can see in the attachment "successVista.jpg".
Of course, in both cases the password is right typed.

dahall wrote Thu at 3:35 PM

Please confirm that issue has also been resolved. I think it has the same resolution as the other one that you said I could close.

Colecas wrote Fri at 8:04 AM

I am not sure that the issue was the same as the other one. Because, I don't get an access denied error.
  • The next code works:
    // Create a new task definition and assign properties
    TaskDefinition td = ts.NewTask();
    td.RegistrationInfo.Description = "Does something";
// Create a trigger that will fire the task at this time every other day
td.Triggers.Add(new DailyTrigger { DaysInterval = 2 });

// Create an action that will launch Notepad whenever the trigger fires
td.Actions.Add(new ExecAction("notepad.exe", "c:\test.log", null));

// Register the task in the root folder
var t = ts.RootFolder.RegisterTaskDefinition(@"Test", td);

// If no exception thrown, then log success
output.WriteLine("Success! Task '{0}' created by '{1}' under '{2}'.", t.Name, t.Definition.RegistrationInfo.Author, t.Definition.Principal);

// Delete task
ts.RootFolder.DeleteTask(@"Test"); *But this one not (The only change is to open the TaskEditDialog):
// Create a new task definition and assign properties
TaskDefinition td = ts.NewTask();
td.RegistrationInfo.Description = "Does something";

// Create a trigger that will fire the task at this time every other day
td.Triggers.Add(new DailyTrigger { DaysInterval = 2 });

// Create an action that will launch Notepad whenever the trigger fires
td.Actions.Add(new ExecAction("notepad.exe", "c:\test.log", null));

// Register the task in the root folder
var t = ts.RootFolder.RegisterTaskDefinition(@"Test", td);

t.Definition.Principal.LogonType = TaskLogonType.Password;
TaskEditDialog editForm = new TaskEditDialog(t,true, true);
editForm.ShowDialog();

// If no exception thrown, then log success
output.WriteLine("Success! Task '{0}' created by '{1}' under '{2}'.", t.Name, t.Definition.RegistrationInfo.Author, t.Definition.Principal);

// Delete task
ts.RootFolder.DeleteTask(@"Test");

Colecas wrote Fri at 8:43 AM

I am not sure that the issue was the same as the other one. Because, I don't get an access denied error.
  • The next code works:
// Create a new task definition and assign properties
TaskDefinition td = ts.NewTask();
td.RegistrationInfo.Description = "Does something";

// Create a trigger that will fire the task at this time every other day
td.Triggers.Add(new DailyTrigger { DaysInterval = 2 });

// Create an action that will launch Notepad whenever the trigger fires
td.Actions.Add(new ExecAction("notepad.exe", "c:\test.log", null));

// Register the task in the root folder
var t = ts.RootFolder.RegisterTaskDefinition(@"Test", td);

// If no exception thrown, then log success
output.WriteLine("Success! Task '{0}' created by '{1}' under '{2}'.", t.Name, t.Definition.RegistrationInfo.Author, t.Definition.Principal);

// Delete task
ts.RootFolder.DeleteTask(@"Test");
  • But this one not (The only change is to open the TaskEditDialog):
// Create a new task definition and assign properties
TaskDefinition td = ts.NewTask();
td.RegistrationInfo.Description = "Does something";

// Create a trigger that will fire the task at this time every other day
td.Triggers.Add(new DailyTrigger { DaysInterval = 2 });

// Create an action that will launch Notepad whenever the trigger fires
td.Actions.Add(new ExecAction("notepad.exe", "c:\test.log", null));

// Register the task in the root folder
var t = ts.RootFolder.RegisterTaskDefinition(@"Test", td);

t.Definition.Principal.LogonType = TaskLogonType.Password;
TaskEditDialog editForm = new TaskEditDialog(t,true, true);
editForm.ShowDialog();

// If no exception thrown, then log success
output.WriteLine("Success! Task '{0}' created by '{1}' under '{2}'.", t.Name, t.Definition.RegistrationInfo.Author, t.Definition.Principal);

// Delete task
ts.RootFolder.DeleteTask(@"Test");

dahall wrote Fri at 6:39 PM

The problem seems to be with how the dialog is converting a saved task that is setup as "Interactive" to a "Password" task. I have duplicated your errors and will work through them in the next release. Until then, the following code works and, I believe, accomplished what you are trying to do.
// Create a new task definition and assign properties
TaskDefinition td = ts.NewTask();
td.RegistrationInfo.Description = "Does something";
td.Principal.LogonType = TaskLogonType.Password;

// Create a trigger that will fire the task at this time every other day
td.Triggers.Add(new DailyTrigger { DaysInterval = 2 });

// Create an action that will launch Notepad whenever the trigger fires
td.Actions.Add(new ExecAction("notepad.exe", "c:\test.log", null));

// Call the dialog with the definition only (not a registered task)
TaskEditDialog editForm = new TaskEditDialog(ts, td, true, true) { TaskName = "Test" };
var r = editForm.ShowDialog();
if (r == System.Windows.Forms.DialogResult.Cancel) return;
Task t = editForm.Task;

// If no exception thrown, then log success
output.WriteLine("Success! Task '{0}' created by '{1}' under '{2}'.", t.Name, t.Definition.RegistrationInfo.Author, t.Definition.Principal);

// Delete task
ts.RootFolder.DeleteTask(@"Test");