2

I'm creating a scheduled task using c# from a MVC app. It works fine, but I am not able to add a BootTrigger:

TaskDefinition td = ts.NewTask();
TaskService ts = new TaskService();
td.RegistrationInfo.Description = "Some Description";
...
td.Triggers.Add(new BootTrigger()); //Leaving this line out, does not give the error.
...
ts.RootFolder.RegisterTaskDefinition("My Task", td);       

The code gives the error:

Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))

Based on other posts I need to run the app As Administrator or add a manifest file with relevant settings, but as this is a MVC site running in IIS these options are not available.

How else can I add a Boot Trigger to a Scheduled Task? Or trigger the task to run at system startup?

Cameron Castillo
  • 2,712
  • 10
  • 47
  • 77
  • If you absolutely needed to solve this and can't figure it out, one option could be to create a secondary app (non-MVC) with a manifest file, and trigger that from your main app. The secondary app would only be responsible for creating tasks. – Tawab Wakil Jul 07 '22 at 16:11
  • I guess it's an option, but as the utility must go to multiple customers, we don't really want them to install/configure a separate app. Will look funny. But it's a sensible idea, but not ideal in our environment. – Cameron Castillo Jul 11 '22 at 14:17

1 Answers1

0

Did you try setting the application pool identity to an administrator? this

Majid325
  • 34
  • 5
  • Not yet. Can try it, although it will change quite a few thinks our side. Not ideal, but perhaps. – Cameron Castillo Jul 13 '22 at 14:08
  • Sadly, this suggestion will not work in our environment as the IIS user is also performing other integration for which Admin will not work. We will create an Azure Service to restart these services on server startup. But the suggestion may work for someone else. – Cameron Castillo Jul 18 '22 at 08:21