Comments (21)
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.
What error are you getting? Are you running the project under UAC? This will restrict even the standard user rights.
from taskscheduler.
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.
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.
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.
can you give me an example of such manifest?
from taskscheduler.
See https://www.codeproject.com/Articles/17968/Making-Your-Application-UAC-Aware
from taskscheduler.
do you mean highestAvailable solves this for standard user?
from taskscheduler.
That is the setting I have used with success in the past.
from taskscheduler.
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...
from taskscheduler.
can you reopen the issue?
from taskscheduler.
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.
Hold on... I'll check on other environments
from taskscheduler.
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.
yes, this works, exactly what I need
from taskscheduler.
Thanks for solve my problem too!
from taskscheduler.
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.
@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.
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.
@DivVishal : Please see all the information on Microsoft's help page for Security Contexts for Tasks.
from taskscheduler.
@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 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)
- Add an Example for TaskService.FindAllTasks Method (Predicate(Task), Boolean)
- Add an Example for TaskPrincipal Class
- Add an Example for TriggerCollection.Remove Method
- TaskScheduler 1,000 Stars. HOT 1
- Task is not created if try with different user HOT 1
- Please update the task security page with info about LocalAccountTokenFilterPolicy HOT 1
- TaskService stores a connection password in clear text HOT 1
- Add an Example for CustomTrigger Class
- Cannot create Task within a AWS EC2 machine HOT 2
- problem with Task when starting from a service HOT 4
- Add an Example for RepetitionPattern Class HOT 1
- Task Fails to run under different user account HOT 5
- Task Does not Create on French OS Computer to English Computer HOT 2
- Using task scheduler with System.Runtime.InteropServices in .NET FRAMEWORK 4.5
- Task Updation fails HOT 2
- Add an Example for TaskService.FindTask Method HOT 1
- Support For Clustered Tasks ? HOT 1
- Does not register task in executable. HOT 1
- `TaskDefinition.Settings.Priority` default value NOT `Normal` HOT 1
- UnauthorizedAccessException without credentials HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from taskscheduler.