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

Closed

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

Closed Oct 6 at 1:29 AM by dahall
Fixed in 2.6.2 - Released today

comments

dahall wrote Jun 27 at 5: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 1:23 PM

Colecas wrote Jun 29 at 1: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 2: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 5:32 PM

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

mpthegr wrote Jul 1 at 6: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 5: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 4:10 PM

Colecas wrote Jul 12 at 4: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 4:23 PM

Colecas wrote Jul 12 at 4: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 Jul 20 at 4: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 Jul 21 at 9: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 Jul 21 at 9: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 Jul 21 at 7: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");

Colecas wrote Aug 22 at 8:25 AM

Hi Dahall,
Do you have news about the issue?

dahall wrote Aug 29 at 4:30 PM

I'm struggling to find the error in the code that would cause this problem only on Vista. My last thought is to ask you to tell me what you see for the "user" in the password prompt. I'm curious if I'm not getting the full user name to pass to the Register method.

Colecas wrote Sep 22 at 2:48 PM

Hello Dahall,
Sorry for my late reply.

Colecas wrote Sep 22 at 2:54 PM

I am trying to attach screenshots, but it doesn't work.
The work around that you proposed doesn't solve my issue. Because I need to register the task before open the dialog, to avoid that the user could change the name of the task.

dahall wrote Sep 22 at 5:47 PM

I have fought with this for a number of hours and cannot find a way around how Microsoft is handling this in Win7. In the next release (2.6.2), I have added a property to TaskEditDialog called 'TaskNameIsEditable' that you can set to false to prevent changes to it. New use would be:
// 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", TaskNameIsEditable = false };
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");

Colecas wrote Sep 25 at 4:06 PM

Thanks Dahall,
I think that it should work for us.
I will test it when the version is available.

Colecas wrote Sep 27 at 11:37 AM

When the version 2.6.2 will be available?

dahall wrote Sep 27 at 5:29 PM

I have also included a .NET Standard 2.0 build in this release, but it hasn't been tested and really can't be fully tested until the next version of VS (15.4) comes out. I'd like to wait until then, but am willing to push it sooner if this is imperative for you. My guess is that if I don't document the new build, very few will use it and potentially find bugs. Please let me know your urgency.

wrote Oct 6 at 1:29 AM