Calling ClickOnce App From Task Scheduler
I have a windows application that I deployed to a file share via ClickOnce (VS 2012). It's configured as an online application (not installed on the client). I can run this application via the client by just pointing to the file share and double-clicking the file. What I'm having a problem doing is running this as a scheduled task on the client (client is actually a server, Windows Server 2008). If however, I create a batch file that calls the ClickOnce app, task scheduler can successfully call the batch file. But I'd rather not have to deal with the extra step of creating that batch file.
The error I get from Task Scheduler is this: Task Scheduler failed to launch action "pathToClickOnceApp" in instance "{d5cc956f-c09e-41dc-a04d-a4276f38704e}" of task "TaskName". Additional Data: Error Value: 2147942403.
You can make an appref-ms file and put it locally where task scheduler starts, or put it on file share (this may require additional permissions like 'execute').
Then make task scheduler launch this file.
以下是创建可调用clickonce应用的任务的示例代码:
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);
}
链接地址: http://www.djcxy.com/p/38942.html