【问题标题】:Start process with WMI on remote machine from a share on another remote machine从另一台远程计算机上的共享启动远程计算机上的 WMI 进程
【发布时间】:2012-01-27 12:41:29
【问题描述】:

我有以下代码从第二台远程计算机上的共享运行远程计算机上的进程,如图所示:


(来源:microsoft.com

public class Runner
{
    public static string RunExecutable(string machine, string executable, string username, string password, string domain)
    {
        try
        {
            ConnectionOptions connectionOptions = new ConnectionOptions();
            connectionOptions.Authority = "kerberos:" + domain + @"\" + machine;
            connectionOptions.Username = username;
            connectionOptions.Password = password;
            connectionOptions.Impersonation = ImpersonationLevel.Delegate;
            connectionOptions.Authentication = AuthenticationLevel.PacketPrivacy;

            //define the WMI root name space
            ManagementScope scope = new ManagementScope(@"\\" + machine + "." + domain + @"\root\CIMV2", connectionOptions);

            //define path for the WMI class
            ManagementPath p = new ManagementPath("Win32_Process");

            //define new instance
            ManagementClass classInstance = new ManagementClass(scope, p, null);

            ManagementClass startupSettings = new ManagementClass("Win32_ProcessStartup");
            startupSettings.Scope = scope;
            startupSettings["CreateFlags"] = 16777216;

            // Obtain in-parameters for the method
            ManagementBaseObject inParams = classInstance.GetMethodParameters("Create");

            // Add the input parameters.
            inParams["CommandLine"] = executable;
            inParams["ProcessStartupInformation"] = startupSettings;

            // Execute the method and obtain the return values.
            ManagementBaseObject outParams = classInstance.InvokeMethod("Create", inParams, null);

            // List outParams
            string retVal = outParams["ReturnValue"].ToString();
            return "ReturnValue: " + retVal;
        }

        catch (ManagementException me)
        {
            return me.Message;
        }

        catch (COMException ioe)
        {
            return ioe.Message;
        }
    }
}

我的环境中有 5 台机器,都在同一个域中。 3 台运行 Windows Server 2008R2,一台 Windows 7 和一台 Windows XP:

  • WinXP
  • Win7
  • Master2008
  • Slave2008-1
  • Slave2008-2

我从域控制器 Master2008 运行代码,并尝试在其他机器上启动进程,但在 XP 和 7 机器上启动进程时遇到了一些问题。

在 WinXP 和 Win7 机器上启动进程时,我得到的返回值为 8,即“未知错误”,但在 Server 2008R2 机器上启动进程时,它可以正常工作。

所有机器都已在 AD 中标记为可信任的委派。

我尝试启动的进程是 \\"machine"\c$\Windows\System32\Calc.exe

我试过在不同的机器上运行这个过程,结果如下(程序在Master2008上运行):

On WinXP
 - From Win7: Failed (8)
 - From Slave2008-1: Failed (8)
 - From Slave2008-2: Failed (8)
 - From Master2008: Failed (8)

On Win7
 - From WinXP: Success (0)
 - From Slave2008-1: Failed (8)
 - From Slave2008-2: Failed (8)
 - From Master2008: Failed (8)

On Slave2008-1
 - From WinXP: Success (0)
 - From Win7: Success (0)
 - From Slave2008-2: Success (0)
 - From Master2008: Success (0)

On Slave2008-2
 - From WinXP: Success (0)
 - From Win7: Success (0)
 - From Slave2008-1: Success (0)
 - From Master2008: Success (0)

由于某种原因,WinXP机器都失败了,但是Win7机器可以从WinXP机器安装。

有谁知道哪里出了问题?

【问题讨论】:

    标签: c# process wmi


    【解决方案1】:

    代码似乎没有问题。我尝试制作一个简单的应用程序来启动而不是“calc.exe”,它可以正常工作。

    问题是我试图在 32 位客户端上从 64 位服务器启动“calc.exe”。此外,Windows7 上的“calc.exe”无法在 WindowsXP 上运行。

    【讨论】:

      【解决方案2】:

      不工作。 http://technet.microsoft.com/en-us/library/ee156574.aspx

      除非事务中涉及的所有用户帐户和计算机帐户都已在 Active Directory 中标记为受信任以进行委派,否则您不能使用代理模拟级别。这有助于最大限度地降低安全风险。尽管远程计算机可以使用您的凭据,但只有当它和事务中涉及的任何其他计算机都受信任以进行委派时,它才能这样做。

      【讨论】:

      • 回答一个标记为已解决的 2 岁问题似乎有点不必要。这些计算机已在 AD 中标记为受信任,这不是问题。
      猜你喜欢
      • 2013-09-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-01-19
      • 1970-01-01
      相关资源
      最近更新 更多