从另一台远程机器的共享文件夹启动远程机器上的进程,使用WMI。

4
我有以下代码,可以从第二台远程机器上的共享文件夹运行一个进程到另一台远程机器上,如下图所示: Connection (来源: 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上运行代码,并尝试在其他机器上启动进程,但在启动WinXP和Win7机器上的进程时遇到了一些问题。
当我在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机器安装。

有人知道可能出了什么问题吗?

2个回答

1

在代码方面似乎没有任何问题。我尝试创建一个简单的应用程序来代替“calc.exe”进行启动,结果它按照预期正常工作。

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


0

不起作用。 http://technet.microsoft.com/zh-cn/library/ee156574.aspx

除非在Active Directory中将涉及事务的所有用户帐户和计算机帐户都标记为可信委派,否则您无法使用委派模式。这有助于最小化安全风险。虽然远程计算机可以使用您的凭据,但只有在涉及的所有计算机都被信任委派时,它才能这样做。


2
回答一个两年前被标记为已解决的问题似乎有点不必要。计算机已经在AD中被标记为可信任,这并不是问题所在。 - Avilan

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接