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

Commented Unassigned: Need to Set "RunOnlyIfLoggedOn" in Ver 2.0 [12031]

$
0
0
I've created a task with a trigger that starts a custom Windows Form application "At log on" of a specific user. In order for the task to succeed in running the application upon log on of the specific user, I must specify the specific user and their password when registering the task definition (ie: ts.RootFolder.RegisterTaskDefinition(taskName, td, TaskCreation.CreateOrUpdate...). I'm able to save/register the task, but the "Run whether user is logged on or not" option gets enabled under the "General > Security options" tab in the Task Manager. Thus, my application cannot start. When I manually change the Security option to "Run only when user is logged on" my application starts fine upon login. The problem is that I cannot set this option programmatically in ver 2.0 of the library.

In addition, I should not have to specify a password in the definition of the task if the "Run only when user is logged on" option is enabled because the user enters a password upon log on. When creating the task in the Task Scheduler manually, it does not prompt for a password.

How can I get this working so my application will start.
Comments: ** Comment from web user: dahall **

The code below should generate the exact format of the XML file you provided:
```
using (var ts = new TaskService())
{
var td = ts.NewTask();
td.RegistrationInfo.Description = "Launches Network Connection Manager upon login.";
td.Principal.RunLevel = TaskRunLevel.Highest;
td.Settings.DisallowStartIfOnBatteries = false;
td.Settings.StopIfGoingOnBatteries = false;
td.Settings.AllowHardTerminate = false;
td.Settings.IdleSettings.StopOnIdleEnd = false;
td.Settings.Hidden = true;
td.Settings.UseUnifiedSchedulingEngine = true;
td.Settings.ExecutionTimeLimit = TimeSpan.Zero;
td.Settings.Priority = System.Diagnostics.ProcessPriorityClass.Normal;
td.Actions.Add(@"M:\NetworkConnectionManager\NetworkConnectionManager.EXE",
null, @"M:\NetworkConnectionManager\");
td.Triggers.Add(new LogonTrigger { UserId = @"JEFFL-PC\GUEST" });
ts.RootFolder.RegisterTaskDefinition("TaskName", td, TaskCreation.CreateOrUpdate,
@"JEFFL-PC\GUEST", null, TaskLogonType.InteractiveToken, null);
}
```


Viewing all articles
Browse latest Browse all 2206

Trending Articles



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