C#WMI Win32_ScheduledJob无法创建 [英] C# WMI Win32_ScheduledJob Failing to create

查看:130
本文介绍了C#WMI Win32_ScheduledJob无法创建的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用简单的c#程序在另一台计算机上远程创建一个作业,如下所示:

Hi,I am trying to remotly create a job on aanother computer using simple c# procedure that looks like:

ConnectionOptions connection = new ConnectionOptions { Username = this.dutConfig.UserName, Password = this.dutConfig.Password, EnablePrivileges = true }; this.wmiScope = new ManagementScope(path: string.Format(@"\\{0}\root\CIMV2", this.dutConfig.IPAddress), options: connection); try { this.wmiScope.Connect(); } catch (Exception e) { var exceptionMessage = string.Format("Management Connect to remote machine {0} failed with the following error {1}", this.dutConfig.IPAddress, e.Message); throw new Exception(exceptionMessage); } try { ObjectGetOptions objectGetOptions = new ObjectGetOptions(); ManagementPath managementPath = new ManagementPath(path: "Win32_ScheduledJob"); ManagementClass classInstance = new ManagementClass(scope: this.wmiScope, path: managementPath, options: objectGetOptions); ManagementBaseObject inParams = classInstance.GetMethodParameters("Create"); inParams["Command"] = "cmd.exe"; inParams["StartTime"] = string.Format("********{0}{1}{2}.000000+{3}", this.currentTime.Hour,this.currentTime.Minute, this.currentTime.Second,240); inParams["InteractWithDesktop"] = true; ManagementBaseObject outParams = classInstance.InvokeMethod("Create", inParams, null); Console.WriteLine("JobId: " + outParams["jobId"]); Console.WriteLine("ReturnValue: " + outParams["returnValue"]); Console.ReadKey(); } catch (ManagementException err) { Console.WriteLine("An error occurred while trying to execute the WMI method: " + err.Message);

}

}

但是遇到问题,JobId没有返回并且返回值是8,我检查的女巫被标记为未指定的故障发生。任何想法可能导致它或在哪里可以深入研究问题?我尝试在power shell中本地创建作业,并且
工作。

But having a problem, JobId is not returning and return Value is 8, witch as i checked is marked as An unspecified failure occurred. Any idea what may cause it or where can i look deeper into a problem?? I tried creating jobs locally in power shell and it worked.

推荐答案

你好WojszaM,

Hi WojszaM,

这个论坛用于讨论WCF开发问题,你的问题与WMI有关,我会把这个帖子移到更多相关论坛。

This forum is used to discuss about WCF developing issue, your issue is more related with WMI, I will move this thread to the more related forum.

参考:
https://social.msdn.microsoft.com/Forums/vstudio/en-US/home?forum=csharpgeneral

感谢您的理解。

最诚挚的问候,

Edward 

Edward 


这篇关于C#WMI Win32_ScheduledJob无法创建的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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