I am trying to schedule the tasks from my application using schtasks instead of using the Windows Task Scheduler COM/managed API.
Creating a task here is easier by using this on command line schtasks /Create /tn "MyApp" /tr c:\myapp.exe /sc onlogon but I opened the command line as an administrator to get the task created (otherwise I get access denied)
From my application, to create the task I use
string args = @"/Create /tn MyApp /tr c:\myapp.exe /sc onlogon";
Process.Start("schtasks", args);
However, the task gets created only if I run my application as an administrator. I need to avoid this, so that any user can create the task without the hassle of running the app as admin. Any suggestions on how ca this be done?
You can try with a sort of RunAs that allow to run a process with a specified user :
The Process class through ProcessStartInfo provides a mechanism which allows you to specify the user context that the new process should run under, so you can specify the user in which you want to run the command even if the user that start the program is different. In your case you can specify Administrator credentials to the ProcessStartInfo without having to run the program with an Administrator user …