从Web应用程序运行计划的任务 [英] Run a scheduled task from web application

查看:66
本文介绍了从Web应用程序运行计划的任务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下代码从我的Web应用程序执行Windows计划任务.Web应用程序和计划的应用程序都在同一服务器上运行.

I am using the following code to execute a Windows Scheduled Task from my web application. Both the web application and the scheduled application runs on the same server.

var proc = new Process
{
    StartInfo =
    {
        UseShellExecute = false,
        FileName = @"C:\Windows\System32\schtasks.exe",
        Arguments = "/run /tn StartDataSync",
        UserName = "admin123",
        Password = passwd
    }
};
proc.Start();
proc.WaitForExit();

现在,我想从在同一网络域中另一台计算机上运行的Web应用程序中运行相同的计划应用程序.研究后,我发现我可以在/S系统参数中指定要连接的远程计算机的名称或IP地址.因此,我尝试了以下代码,但无法正常工作.

Now I would like to run the same scheduled application from a web application running on another machine in the same network domain. When I researched I found like I can specify the name or IP address of the remote computer I want to connect to in the /S system argument. So I tried the following code, but its not working.

var proc = new Process
{
    StartInfo =
    {
        UseShellExecute = false,
        FileName = @"C:\Windows\System32\schtasks.exe",
        Arguments = "/run /S 192.168.5.202 /tn StartDataSync",
        UserName = "admin123",
        Password = passwd
    }
};
proc.Start();
proc.WaitForExit();

推荐答案

尝试此答案..根据此

Try this answer ..according to this post

using TaskScheduler;

using (TaskService tasksrvc = new TaskService(server.Name, login, domain, password))
{
    Task task = tasksrvc.FindTask(taskName);
    task .Run();       
}

可以在此处 https://github.com/dahall/taskscheduler 中找到用于任务计划程序的

dll.

dll for task scheduler can be found here https://github.com/dahall/taskscheduler

这篇关于从Web应用程序运行计划的任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆