【问题标题】:C# WMI remote process executionC# WMI 远程进程执行
【发布时间】:2012-10-02 12:42:47
【问题描述】:

我正在尝试运行一个调用 Win 2008 机器上的批处理文件的命令。 (我登录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"];

感谢任何帮助...

【问题讨论】:

  • 这段代码执行后的ReturnValue值是多少?
  • 返回值为0..我想是在没有错误的情况下返回的。
  • 然后该命令已执行,但对您不可见。因为 create 方法不能用于远程启动交互式进程。
  • 该命令执行 DD exe 来创建系统映像。所以在这种情况下 DD.exe 应该出现在任务管理器中。它不会出现在那里 :(
  • 任务管理器中没有显示进程dd.exe?

标签: c# .net c#-4.0 wmi


【解决方案1】:

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

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

【讨论】:

    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多