Git Product home page Git Product logo

Comments (21)

dahall avatar dahall commented on June 6, 2024 5

After doing a little more research and testing, I found that in order to use the LogonTrigger as a non-privileged user you must specify the current user's account (DOMAIN\username) in the UserId property and register the task as either interactive (default) or with the user account and password.

The following will work.

var td = ts.NewTask();
td.Actions.Add("notepad", null, null);
td.Triggers.Add(new LogonTrigger { UserId = System.Security.Principal.WindowsIdentity.GetCurrent().Name });
ts.RootFolder.RegisterTaskDefinition("Test", td);

Given this, I will be updating this library to automatically set that property in this condition.

from taskscheduler.

dahall avatar dahall commented on June 6, 2024

What error are you getting? Are you running the project under UAC? This will restrict even the standard user rights.

from taskscheduler.

gusarov avatar gusarov commented on June 6, 2024

No, I need this for unprivileged user, not administrator. Any unprivileged user can create a task for himself via UI snap-in, there is no problem with this... I'm just looking for a way to do that on C# instead of UI.
There are already lots of tasks scheduled by other software, so, should be possible... None of that software ever been installed or executed under administrator. I almost never use administrator account.
image
What do you mean by 'UAC restricts standard user rights'? It does not matter for unprivileged user, I can disable UAC completely... for standard user UAC only helps to obtain the administrator (other user) token more fluently, there is no way to elevate standard user.

System.UnauthorizedAccessException
  HResult=0x80070005
  Message=Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
  Source=<Cannot evaluate the exception source>
  StackTrace:
<Cannot evaluate the exception stack trace>
   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)

from taskscheduler.

dahall avatar dahall commented on June 6, 2024

UAC can affect unprivileged users. It is an extra level of restrictions placed on all users. If you have not modified the application manifest to allow for maximum permissions, many of the features of the library will not work. This is why the Task Scheduler applet in Windows works: the manifest opens the rights, as do the Dropbox and Google installers. Please try and let me know if you still experience the problems.

from taskscheduler.

gusarov avatar gusarov commented on June 6, 2024

can you give me an example of such manifest?

from taskscheduler.

dahall avatar dahall commented on June 6, 2024

See https://www.codeproject.com/Articles/17968/Making-Your-Application-UAC-Aware

from taskscheduler.

gusarov avatar gusarov commented on June 6, 2024

do you mean highestAvailable solves this for standard user?

from taskscheduler.

dahall avatar dahall commented on June 6, 2024

That is the setting I have used with success in the past.

from taskscheduler.

gusarov avatar gusarov commented on June 6, 2024

this is not working... (not surprisingly) Issue is still open for me...
Honestly, there is nothing new for me on your link. There is nothing specific about tasks.
Can you send working example?
I don't understand why do you keep talking about UAC. I can disable it completely and still will be able to use Task Scheduler UI or install Google Chrome for user with tasks...
image

from taskscheduler.

gusarov avatar gusarov commented on June 6, 2024

can you reopen the issue?

from taskscheduler.

dahall avatar dahall commented on June 6, 2024

UAC for unprivileged accounts is the problem 90% of users experience with this library. It is working for literally tens of thousands of people. Let's try a different tact. Can you create any task? This may be a problem with trigger permissions. Try the following and let me know if successful:
TaskService.Instance.AddTask("Test", QuickTriggerType.Daily, "notepad");

from taskscheduler.

gusarov avatar gusarov commented on June 6, 2024

Hold on... I'll check on other environments

from taskscheduler.

gusarov avatar gusarov commented on June 6, 2024

No, it is not working. Same result. I don't think there is anything special about me. I do all my tests on a clean new virtual machines. If this is difficult for you to test under standard user, can you give a zip example and I'll just compile & run it on different virtual machines?

from taskscheduler.

gusarov avatar gusarov commented on June 6, 2024

yes, this works, exactly what I need

from taskscheduler.

hetianqi avatar hetianqi commented on June 6, 2024

Thanks for solve my problem too!

from taskscheduler.

DivVishal avatar DivVishal commented on June 6, 2024

I am facing same issue of access denied when trying to register task scheduler grammatically with Administrator privileges while running application on non admin user profile. I went through all above comments and trying to fix but didn't get success yet. Below is code. Appreciate any help.

 using (TaskService ts = new TaskService())
 {
   TaskDefinition td = ts.NewTask();
   td.Settings.DeleteExpiredTaskAfter = TimeSpan.FromMinutes(1);
   td.Settings.Hidden = true;
   td.Principal.RunLevel = TaskRunLevel.Highest;
   
   td.Principal.UserId = "Domain\\Administrator_username";   //specified administrator details                  
   
   LogonTrigger trigger = new LogonTrigger();                        
   trigger.UserId = "Domain\\Administrator_username";                      
   trigger.StartBoundary = DateTime.Now.AddSeconds(15);
   trigger.EndBoundary = DateTime.Now.AddMinutes(5);
   td.Triggers.Add(trigger);                       
   
   td.Actions.Add(new ExecAction(filepath, updateArguments, null));
   ts.RootFolder.RegisterTaskDefinition("Updatesoft", td, TaskCreation.Create, "Domain\\Administrator_username");
}

from taskscheduler.

dahall avatar dahall commented on June 6, 2024

@DivVishal : No way around this. You cannot register a task that has more privileges than the account requesting the registration. You also cannot register another account without a password unless that account is a system account.

from taskscheduler.

DivVishal avatar DivVishal commented on June 6, 2024

Thanks dahall for response. Will it work if we create one domain service account and give privileges as built-in Administrator, then use its credentials to register?

from taskscheduler.

dahall avatar dahall commented on June 6, 2024

@DivVishal : Please see all the information on Microsoft's help page for Security Contexts for Tasks.

from taskscheduler.

longhibianca avatar longhibianca commented on June 6, 2024

@dahall Hello!! I'm having the same problem. I have a WPF application that needs to execute a exe for installing a program. To do this I'm creating a task scheduler that contains at path cmd.exe and for arguments the executable path. But when i try to create a task in my own computer, passing computer name, domain, user and password I receive "Unauthorazed error". Stranger is when I pass to computer name a nome of a server or other computer it works very well. How is possible I can create a task in other computer but in my not?
I create taskservice as bellow:
using (TaskService ts = new TaskService(@"\\MyComputer", "username", "domain", "password")) { }

from taskscheduler.

dahall avatar dahall commented on June 6, 2024

@dahall Hello!! I'm having the same problem. I have a WPF application that needs to execute a exe for installing a program. To do this I'm creating a task scheduler that contains at path cmd.exe and for arguments the executable path. But when i try to create a task in my own computer, passing computer name, domain, user and password I receive "Unauthorazed error". Stranger is when I pass to computer name a nome of a server or other computer it works very well. How is possible I can create a task in other computer but in my not? I create taskservice as bellow: using (TaskService ts = new TaskService(@"\\MyComputer", "username", "domain", "password")) { }

@longhibianca See this help link. Use null or "" for a local computer.

from taskscheduler.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.