YZlat
asked on
Scheduled task security context dilemma
I have a scheduled task that runs exe which is a windows application. In order to see UI, I need to check "run only if user is logged on", but when I create a scheduled task I cannot specify which user it will run under, so if I specify System account, the exe will run without user interface. User interface only shows up if I run the task as myself while I am logged on.
The thing is that the task will be created on multiple machines and will have to run in logged in user context and be interractive. How can I accomplish that?
the task is created programmatically, using C# and Microsoft.Win32.TaskSchedu ler namespace
Can anyone help??
The thing is that the task will be created on multiple machines and will have to run in logged in user context and be interractive. How can I accomplish that?
the task is created programmatically, using C# and Microsoft.Win32.TaskSchedu
Can anyone help??
ASKER
My question is more specific. And the example you posted does not require user interface, it runs on a background.
I already have all that code and it is fine running on a background under System account. I need it to run under user account of currently logged in user
I already have all that code and it is fine running on a background under System account. I need it to run under user account of currently logged in user
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
what kind of account is builtin\users??
Will it enable the scheduled task to run an exe with UI?
Will it enable the scheduled task to run an exe with UI?
ASKER
I tried that group and got an error "This LogonType is not supported on Task Scheduler 1.0"
It is a group account All computer users are members of this group. Yes I tested it with Notepad and it ran fineNotepad-Test.xml
ASKER
Here is the code that gave me this error "This LogonType is not supported on Task Scheduler 1.0"
using (TaskService ts = new TaskService())
{
TaskDefinition td = ts.NewTask();
td.RegistrationInfo.Description = "task that runs exe";
TimeTrigger tt = new TimeTrigger();
tt.Enabled = true;
tt.StartBoundary = DateTime.Now + TimeSpan.FromMinutes(5);
tt.Repetition.Interval = TimeSpan.FromHours(1);
td.Triggers.Add(tt);
td.Principal.RunLevel = TaskRunLevel.Highest;
td.Actions.Add(new ExecAction("MyService.exe", null, Environment.GetEnvironmentVariable("windir")));
ts.RootFolder.RegisterTaskDefinition("MyService", td, TaskCreation.Create, @"BUILTIN\Users", null, TaskLogonType.Group, null);
}
ASKER
I also tried to setup a scheduled task manually and use BUILTIN\Users group and got an error in EventViewer Security log:
Logon Failure:
Reason: Unknown user name or bad password
User Name: Users
Domain: BUILTIN
Logon Failure:
Reason: Unknown user name or bad password
User Name: Users
Domain: BUILTIN
ASKER
I modified the task manually to run as BUILTIN\Users and it did not run on a scheduld time. I selected "Run only if logged on" checkbox
that dll doesn't have all the bases covered..
edit the .xml that I provided and then execute
schtasks /create /tn "notepadtest" /xml notepad-test.xml /f
the time is in UTC
edit the .xml that I provided and then execute
schtasks /create /tn "notepadtest" /xml notepad-test.xml /f
the time is in UTC
ASKER
I tried adding BUILTIN\Users to tak manually but it can only add 'ComputerName\Users' or 'DOMAINNAME\Domain users'
And I found that BUILTIN\Users only good for Windows 7 but does not work on Windows XP, so my problem still stays unsolved:(
And I found that BUILTIN\Users only good for Windows 7 but does not work on Windows XP, so my problem still stays unsolved:(
ASKER
Do you have any other suggestions? You cam closer than anyone else so far
What dll were you talking about?
What dll were you talking about?
ASKER
Looks like BUILTIN\Users worked for Windows 7. But what do I do with Windows XP?
ASKER
Turns out I do not need it for windows xp, only for windows 7.
Thanks a lot!
Thanks a lot!
ASKER
Thank you! You are the best!
http://msdn.microsoft.com/en-us/library/windows/desktop/aa382140%28v=vs.85%29.aspx
http://taskscheduler.codeplex.com/wikipage?title=Examples&referringTitle=Documentation