Quantcast
Channel: Task Scheduler Managed Wrapper
Viewing all articles
Browse latest Browse all 2206

New Post: How to set the "Run whether user is logged on or not"

$
0
0

How can I set the "Run whether user is logged on or not" option?

I would like use this to ensure that a scheduled task run 5min aftet at startup.

 

    String strPath;

            BootTrigger cBootTrigger;
            cBootTrigger = new BootTrigger();
            cBootTrigger.Delay = new TimeSpan(0, 5, 0);

            strPath = "c:\\MyAPP.exe";
            using (TaskService ts = new TaskService())
            {
                TaskFolder tf = ts.RootFolder;

                // Create a new task definition and assign properties
                TaskDefinition td = ts.NewTask();
                td.RegistrationInfo.Description = "MyAppAtBoot";
               
                td.Principal.LogonType = TaskLogonType.InteractiveToken;

                    // Create a trigger that will fire the task at this time every other day
                    td.Triggers.Add(cBootTrigger);

                    // Create an action that will launch Notepad whenever the trigger fires
                    td.Actions.Add(new ExecAction(strPath, null, null));

                    // Register the task in the root folder
                    try
                    {

                        ts.RootFolder.RegisterTaskDefinition(@"MyAppAtBoot", td);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.ToString());

      }
               
            }

 


Viewing all articles
Browse latest Browse all 2206

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>