C#WMI远程进程执行

C#WMI远程进程执行,c#,.net,c#-4.0,wmi,C#,.net,C# 4.0,Wmi,我正在尝试运行一个命令,该命令调用Win 2008 box上的批处理文件。(当我登录Win 2008并单击时,命令将成功运行) 但是,当我使用相同的用户凭据通过WMI调用此批处理文件时,批处理不会执行 我要连接的代码是: ConnectionOptions connOptions = new ConnectionOptions(); connOptions.Impersonation = ImpersonationLevel.Impersonate; connOptions.EnablePriv

我正在尝试运行一个命令,该命令调用Win 2008 box上的批处理文件。(当我登录Win 2008并单击时,命令将成功运行)

但是,当我使用相同的用户凭据通过WMI调用此批处理文件时,批处理不会执行

我要连接的代码是:

ConnectionOptions connOptions = new ConnectionOptions();
connOptions.Impersonation = ImpersonationLevel.Impersonate;
connOptions.EnablePrivileges = true;
connOptions.Username = UserName;
connOptions.Password = Password;

ManagementScope manScope = new ManagementScope(
    String.Format(@"\\{0}\ROOT\CIMV2", ComputerName), connOptions);
manScope.Connect();

ObjectGetOptions objectGetOptions = new ObjectGetOptions();
ManagementPath managementPath = new ManagementPath("Win32_Process");
ManagementClass processClass = new ManagementClass(
    manScope, managementPath, objectGetOptions);

ManagementBaseObject inParams = processClass.GetMethodParameters("Create");

inParams["CommandLine"] = command;
ManagementBaseObject outParams = processClass.InvokeMethod("Create", inParams, null);
Object returnValue = outParams["ReturnValue"];

非常感谢您的帮助……

当通过WMI在远程计算机上实例化命令时,您需要指定显式凭据。WMI增强了安全性,但这样做实际上降低了安全性,因为与令牌不同,显式凭据以明文形式传递它们。

如果将ROOT\CIMV2设置为服务器上脚本的默认命名空间,则您只需要以下内容:

ManagementScope manScope = new ManagementScope(
    String.Format(@"\\{0}", ComputerName), connOptions);
manScope.Connect();

执行此代码后的返回值是什么?返回值是0。。我想这是在没有错误的情况下返回的。然后命令被执行了,但是您看不见。因为无法使用create方法远程启动交互进程。该命令执行DD exe以创建系统映像。。因此,在这种情况下,DD.exe应该显示在任务管理器中。。它没有显示在那里:(任务管理器中没有显示进程dd.exe?