【发布时间】: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机器安装。
有谁知道哪里出了问题?
【问题讨论】: