本文介绍了C#启动定时任务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试用 C# 编写一个简单的表单,该表单将在某些计算机上运行计划任务.到目前为止,我所拥有的是:

I'm trying to write a simple form in c# that will run a scheduled task one some computers.Whet I have so far is:

private void button_Click(object sender, EventArgs e)
    {
        try
        {

            for (int i = 0; i < num_of_computers; i++)
            {
                string line;
                line = (" /run /tn myTask /s " + _ReplacerObj.MyComputers[i] + " /u user s /p password");
                proc.WindowStyle = System.Diagnostics.ProcessWindowStyle.Minimized;
                proc.FileName = @"C:\WINDOWS\SYSTEM32\schtasks.exe";
                proc.Arguments = line;
                Process.Start(proc);
            }
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.ToString(), "Error Message!");
        }

出于某种原因,这不起作用(即 - 计划任务未启动).我尝试从 cmd 运行:

For some reason this doesn't work (IE - the scheduled task didn't start). I tried running from cmd this:

c:\windows\system32\schtasks.exe /run /tn myTask /s myIp /u user /p password

而且效果很好.有什么建议?谢谢!

and it worked fine.Any suggestions?THANKS!

推荐答案

我建议为任务调度程序使用 .NET 包装器之一.

I suggest using one of the .NET wrappers for the task scheduler.

我过去使用过这个,效果很好.

I have used this one in the past to good effect.

这篇关于C#启动定时任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 22:54