Scheduled task security context dilemma

YZlat
YZlat used Ask the Experts™
on
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.TaskScheduler namespace

Can anyone help??
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Author

Commented:
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
Top Expert 2016
Commented:
use the account builtin\users

Author

Commented:
what kind of account is  builtin\users??

Will it enable the scheduled task to run an exe with UI?

Author

Commented:
I tried that group and got an error "This LogonType is not supported on Task Scheduler 1.0"
Top Expert 2016

Commented:
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

Author

Commented:
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);

                    
                }

Open in new window

Author

Commented:
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

Author

Commented:
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
Top Expert 2016

Commented:
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

Author

Commented:
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:(

Author

Commented:
Do you have any other suggestions? You cam closer than anyone else so far

What dll were you talking about?

Author

Commented:
Looks like BUILTIN\Users worked for Windows 7. But what do I do with Windows XP?

Author

Commented:
Turns out I do not need it for windows xp, only for windows 7.

Thanks a lot!

Author

Commented:
Thank you! You are the best!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial