Win32_scheduledjob没有在C#中返回任何结果? [英] Win32_scheduledjob is not returning any result in C# ?

查看:95
本文介绍了Win32_scheduledjob没有在C#中返回任何结果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好我使用下面的代码来获取窗口7中的所有任务时间表



hi all i am using below code to fetch the All Task Schedule in window 7

ManagementScope scope = new ManagementScope("\\\\.\\ROOT\\cimv2");

          string query = "SELECT * FROM Win32_ScheduledJob";

          ManagementObjectSearcher searchCom;
          ManagementObjectCollection moCollection;
          WqlObjectQuery result = new WqlObjectQuery(query);
          searchCom = new ManagementObjectSearcher(scope,result);
          moCollection = searchCom.Get();





但它不会让任何结果退缩。

谁能告诉我什么是错的在上面的代码中?



TIA



我尝试了什么:



我在google上搜索但没有得到任何解决方案



but it is not returing any result.
can anyone tell me what is wrong in above code?

TIA

What I have tried:

I search on google but did not get any solution

推荐答案

原因是此调用内部使用旧的AT协议(即NT风格,就像旧的AT命令一样),而不是那些在任务调度程序中创建的协议。



参见eg [ ^ ]



但是关于我们如何在Win8 / WinSrv2012及其他地方远程完成所有其他工作的明显问题我很遗憾没有答案...



ADD:

使用此MicroSoft Nuget软件包找到解决方案:

The reason is that this call internally uses the old AT protocol (that is NT-style, like the old AT command), and not those created in say the Task Scheduler.

see e.g. [^]

But the obvious question on how we get to all the rest, on Win8/WinSrv2012 and beyond remotely I unfortunately does not have an answer for...

ADD:
Found a solution with this MicroSoft Nuget package:
using Microsoft.Win32.TaskScheduler;

using (TaskService ts = new TaskService(


\\\\ {host},用户名,domName,密码)){
任务[] tasks = ts.FindAllTask​​s(new System.Text.RegularExpressions.Regex(。),true);
foreach(任务中的任务任务){
TaskPrincipal princ = task.Definition.Principal;
Console.WriteLine(
"\\\\{host}", username, domName, password)) { Task[] tasks = ts.FindAllTasks(new System.Text.RegularExpressions.Regex("."),true); foreach(Task task in tasks) { TaskPrincipal princ = task.Definition.Principal; Console.WriteLine(


{host} SchedJob:'{task.Name}'usr:'{princ.UserId}'已启用:{task.Enabled})
}
}
"{host} SchedJob:'{task.Name}' usr:'{princ.UserId}' Enabled:{task.Enabled}") } }


这篇关于Win32_scheduledjob没有在C#中返回任何结果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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