【问题标题】:Remote scheduled task status远程计划任务状态
【发布时间】:2012-06-27 22:51:39
【问题描述】:

对于我的应用程序,我想监控远程服务器上特定计划任务的“状态”选项卡,并根据该状态执行操作。即,如果任务尚未运行,则运行它等。

截至目前,我正在将 cmd.exe 作为 C# 中的进程启动,将该机器的 schtask psexec'ing 到一个文本文件中,读取该文本文件,然后执行相应的操作。

是否有更好的方法来执行此过程(获取 schtask 的特定状态)而不涉及第 3 方开源库?

【问题讨论】:

标签: c# .net scheduled-tasks psexec


【解决方案1】:

您可以尝试使用原生的TaskService COM API:

//add reference to the 'Task Scheduler 1.1 Type Library'

using TaskScheduler;

//...

TaskSchedulerClass ts = new TaskSchedulerClass();
ts.Connect(remotehost, user, domain, password);
IRunningTaskCollection tasks = ts.GetRunningTasks(1);
foreach (IRunningTask task in tasks)
{
    Console.WriteLine(task.Name);
}

有关安全和权限的一些任务,请参阅http://msdn.microsoft.com/en-us/library/windows/desktop/aa382140(v=vs.85).aspx

或者,如果 powershell 是一个选项,可能会更容易,具体取决于版本。

【讨论】:

    【解决方案2】:
    猜你喜欢
    • 1970-01-01
    • 2016-07-20
    • 1970-01-01
    • 2013-10-15
    • 2019-03-29
    • 1970-01-01
    • 2015-01-04
    • 1970-01-01
    • 2011-11-28
    相关资源
    最近更新 更多