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: jeffl012 **
Yes, but the problem is I cant use the InteractiveToken because I must run the task as a different user. Also, the different user's password is unknown. This task definition can be set up manually the way I'm describing, or via the schtasks.exe command line utility. For now, I've written a supplemental addition to the taskscheduler code as a workaround using the schtasks utility. But this is less than desirable:
private void setLaunchTaskLogonUser()
{
ProcessStartInfo procSchtaskInfo = new ProcessStartInfo(Environment.SystemDirectory + "\\schtasks.exe", "/change /RU " + settings.Default.Gen_StartOnLoginUser + " /TN Launch_Network_Manager")
{
CreateNoWindow = true,
RedirectStandardOutput = true,
RedirectStandardError = true,
RedirectStandardInput = true,
UseShellExecute = false
};
Process procSchtask = Process.Start(procSchtaskInfo);
procSchtask.Start();
procSchtask.StandardInput.WriteLine((char)Keys.Return); //required to enter no password when prompted
procSchtask.WaitForExit();
procSchtask.Close();
return;
}
Using this workaround, I know have a task that was created by an administrator, but run as a Standard User under the standard user's account.