-
Notifications
You must be signed in to change notification settings - Fork 197
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Task Fails to run under different user account #976
Comments
I do this all the time, but I don't do it like you are,
It should also let you create a task for yourself without a password but if you want to be your user, and to make a task for any other user as a user, even as admin, you will need the password. This may not help you, but I hope it solves your issue or at least gives you a path to what you want. |
with azure users, the user can make the task for himself, I have not tried to get an azure user to make a task for an azure user. |
Thank you for your response. The only significant differences in our approaches were that you set I have changed it to set the td.Principal.UserId, as well as the option to set the username & password in the RegisterTaskDefinition (as we were doing before), and it still does not work to try to run the task from the task scheduler when logged in as another admin user. However, if we do as that link I provided in my original post suggests and and export, delete and reimport the task, then it will run as desired. if it helps, here's a massaged version of the my code that creates the task: using (TaskService ts = new TaskService())
{
if (ts.FindTask(Name) != null)
{
// handle task already existing
return ;
}
TaskDefinition def = ts.NewTask();
def.RegistrationInfo.Description = Name; // Name defined elsewhere
def.Actions.Add(new ExecAction(Program, Parameters)); // Program and Parameters defined elsewhere
def.Triggers.Add(OneTrigger); // OneTrigger defined elsewhere
def.Settings.IdleSettings.IdleDuration = new TimeSpan(0, IdleWaitMinutes, 0);
def.Settings.Priority = System.Diagnostics.ProcessPriorityClass.Normal;
if (OneTrigger.EndBoundary != DateTime.MaxValue)
def.Settings.DeleteExpiredTaskAfter = new TimeSpan(7, 0, 0, 0);
def.Principal.RunLevel = TaskRunLevel.Highest;
def.Principal.UserId = RunnerUser;
try
{
ts.RootFolder.RegisterTaskDefinition(Name, def, TaskCreation.CreateOrUpdate, RunnerUser, RunnerPwd, TaskLogonType.Password);
}
catch (Exception ex)
{
ts.RootFolder.DeleteTask(Name); // so that there's not some 'bad' task hanging out there...
// handle exception
}
} Thank you for your comments and suggestions. |
I'm semi confused by the ad hoc run part of your requirement, but if the task exists for the the user in question without a trigger they could run the task from task scheduler at any time. But i may just not understand exactly what you meant. |
Describe the bug
After creating a task to run for one user (with highest privileges), it will run for that user. But if you log in as another user, it will not run, saying the user does not have permission.
To Reproduce
Steps to reproduce the behavior:
Expected behavior
I expect the task to run, however it gives a permissions error.
Environment (please complete the following information):
Additional context
As per https://learn.microsoft.com/en-us/answers/questions/707600/task-scheduler-the-user-account-does-not-have-perm
if one exports the task to xml, deletes the task and then imports it, it will then work for all uses. Or if I run the powershell script (there's a link to it from that page) on the task, it will work. It has to do with some permissions being now stored in the registry.
I have done done some searching but can't find a similar posting to this, but apologize if this is a duplicate or if it is handled by code somehow already.
The text was updated successfully, but these errors were encountered: