This project has moved and is read-only. For the latest updates, please go here.

Entry for All Users?

Dec 22, 2010 at 10:11 PM
Edited Dec 22, 2010 at 10:16 PM

Hey everyone, recently my old boss asked me to help with a coding project of his, and in it he uses this library to add a startup entry for the main application. It is assumed the user is the administrator of the PC and can supply the username/password.

Currently, we are able to add an entry for the account that runs it;  but that's the extent of it. When we look at the properties of the added entry, the logon trigger states that it is set to run for Any User, but it never starts up on the other accounts (some of which are not the administrative accounts, but if the password is supplied, shouldn't it work correctly?). It's also set to Run only when the user is logged on (does that mean only when the admin account is logged in, or only when any account is logged in?). Also note: there are no entries for our program shown on the other accounts' Task Schedulers at all.


Can someone please tell me how I can make an entry for All Users, and not just the specific account?


Here is what we have at the moment:


private void useTS()
                using (TaskService ts = new TaskService())
                    TaskFolder tf = ts.RootFolder;
                        TaskDefinition td = ts.NewTask();
                        td.Data = _name;
                        td.Principal.UserId = null;
                        td.Principal.LogonType = TaskLogonType.InteractiveToken; 
                        td.RegistrationInfo.Author = _company; td.RegistrationInfo.Description = _descrip; td.Settings.DisallowStartIfOnBatteries = false; td.Settings.Enabled = true; td.Settings.Hidden = false; td.Settings.Priority = System.Diagnostics.ProcessPriorityClass.Normal; td.Settings.RunOnlyIfIdle = false; td.Settings.RunOnlyIfNetworkAvailable = false; td.Settings.StopIfGoingOnBatteries = false; td.Principal.RunLevel = TaskRunLevel.Highest; td.RegistrationInfo.Source = _name; td.RegistrationInfo.Version = new Version(2, 6); td.Settings.AllowDemandStart = true; td.Settings.AllowHardTerminate = true; td.Settings.Compatibility = TaskCompatibility.V2; td.Settings.DeleteExpiredTaskAfter = TimeSpan.FromMinutes(1); td.Settings.StartWhenAvailable = true; td.Settings.WakeToRun = false; td.Settings.RestartCount = 5; td.Settings.RestartInterval = TimeSpan.FromSeconds(100); LogonTrigger lTrigger = (LogonTrigger)td.Triggers.Add(new LogonTrigger()); lTrigger.Delay = TimeSpan.FromMinutes(1); lTrigger.EndBoundary = DateTime.Today + TimeSpan.FromDays(9999); td.Actions.Add(new ExecAction(textBox8.Text + ".exe", "", textBox7.Text)); tf.RegisterTaskDefinition(_name, td, TaskCreation.CreateOrUpdate, null, null, TaskLogonType.InteractiveToken, null); } catch (Exception ex) { MessageBox.Show("Task Scheduler Entry Failed: " + ex.Message); } } } catch (Exception usTSExcep) { } }


Jan 3, 2011 at 5:33 AM
Edited Jan 12, 2011 at 8:53 PM

The LogonTrigger is associated only with the account that registers the task and will not fire for any other account. I am not aware of any way to use a system account to register a task to be run at each user's logon. To accomplish what you are after, given the need to run an executable, I would suggest not using the Task Scheduler and instead placing a shortcut in the Startup folder of the "All Users". It is different on each version of Windows, but you can look it up as a named folder. The LogonTrigger will be associated with all accounts if the UserId property is set to null and the account registering the task is an adminstrator (technical reference here). If the task can be run at system startup before any user logs on, you can use the BootTrigger.

Jan 12, 2011 at 7:28 PM

Thanks for the suggestion, but we already tried that and it can't be done with Vista or 7. On Vista or 7, no program that requires Administrative privileges can start with Windows through the startup folder or registry Run entry. Microsoft's User Account Control will automatically block any and all programs that require administrator access from within the normal startup routine...

That's the whole reason we tried using the Task Scheduler, because it's the only ways we've been able to get the program loading with the correct permissions at startup.

We've tried using a service, but the service ALWAYS, no matter what, runs on the SYSTEM user account and is only capable of starting the application in a SYSTEM account as well. The SYSTEM account is incapable of elevating any process to Administrator; regardless of how its opened, it always opens as SYSTEM.

And we can't create another admin-based program to elevate it, because there's no way to elevate the first one in the chain, so we'd be back to square one.

I don't understand how other programs requiring administrative privileges are capable of starting up with Windows and not running into such problems...

About your suggestion for the BootTrigger, I'm wondering if it would work. The program will not start up beyond InitializeComponent() unless an internet connection is available to check the license with the server, so I'm curious to know if this program would actually startup correctly.... Sound like an adventure, I'm down to try it and will come back and report on it.


Thanks again for the help =)

Jan 12, 2011 at 8:54 PM

Please see my correction above.