question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable to add a task - AccessDenied

See original GitHub issue

In Windows any unprivileged user can create a task for yourself in Interactive Token mode (“run only when user is logged on”). Looks like I can’t do that via TaskService. I’ve tried 2 ways:

	TaskService.Instance.AddTask("app_"+sid, QuickTriggerType.Logon, path, "-agent");

and

	using (var ts = new TaskService())
	{
		var td = ts.NewTask();
		td.Actions.Add(path, "-agent");
		var tr = td.Triggers.AddNew(TaskTriggerType.Logon);
		td.Principal.LogonType = TaskLogonType.InteractiveToken;
		ts.RootFolder.RegisterTaskDefinition("app_" + sid, td);
	}

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:21 (9 by maintainers)

github_iconTop GitHub Comments

5reactions
dahallcommented, Apr 25, 2018

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.

0reactions
dahallcommented, Nov 10, 2022

@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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Task Manager gives me an access denied error when I try ...
1. Open Task Manager. Go to the Process Tab. 2. Right-click on the GoogleToolbarNotifier Process and click on Properties. 3. Click on ...
Read more >
"Access Denied" or other errors when you access or work ...
Issue 1: I receive an "Access Denied" error message when I try to access or work with files and folders · Press and...
Read more >
windows - unable to schedule a task (access denied)
Proceed with scheduling task or whatever you were doing before getting the dreaded "Access Denied" Error. Hope this helps!
Read more >
c# - .NET create scheduled task on server fails with ...
I've done some searching, and the suggested resolution is to use the web.config 'impersonate' flag to force the application to run as a...
Read more >
Solved: cannot create scheduled task, access denied
The new task could not be created. The specific error is: 0x80070005: Access is denied. Try using the Task page Browse button to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found