Calling the ClickOnce Application from the Task Scheduler

I have a Windows application that I deployed to share files through ClickOnce (VS 2012). It is configured as an online application (not installed on the client). I can run this application through the client by simply pointing to the file share and double-clicking the file. I had a problem running this as a scheduled task on the client (the client is actually a Windows Server 2008 server). If, however, I create a batch file that invokes the ClickOnce application, the task scheduler can successfully invoke the batch file. But I would prefer not to deal with the extra step of creating this batch file.

The error I get from the Task Scheduler is this: The Task Scheduler could not start the action "\ pathToClickOnceApp" in the instance "{d5cc956f-c09e-41dc-a04d-a4276f38704e}" of the task "\ TaskName". Additional information: Error value: 2147942403.

+4
source share
2 answers

You can create the appref-ms file and place it locally when the task scheduler starts, or put it in the file share (this may require additional permissions, such as "execute").

Then run this task scheduler.

0
source

Here is sample code for creating a Task that can invoke a clickonce application:

using (TaskService ts = new TaskService()) { // Create a new task definition and assign properties TaskDefinition td = ts.NewTask(); td.RegistrationInfo.Description = "runs clickonce app every 10 minutes"; var trigger = new TimeTrigger(); trigger.Repetition.Interval = TimeSpan.FromMinutes(10); // Create a trigger that will fire the task at this time every other day td.Triggers.Add(trigger); // Create an action that will launch the clickonce app td.Actions.Add(new ExecAction("rundll32.exe", @"dfshim.dll,ShOpenVerbApplication your_clickonce_app_url/clickonce_appname.application", null)); // Register the task in the root folder ts.RootFolder.RegisterTaskDefinition(@"ClickOnce app", td); } 
0
source

All Articles