我有以下代码来作为图像中所描述的远程计算机上从一个共享第二远程机器上运行的过程:使用WMI远程机器上从共享另一远程计算机上启动过程
Connection http://i.msdn.microsoft.com/dynimg/IC116011.png
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返回值,这是“未知错误”的过程,但开始对服务器2008R2的机器它的工作原理没有问题的过程时。
所有的机器已被标示为公元委派信任。
我试图启动的过程是\\“机” \ C $ \ Windows \ System32下\ CALC.EXE
我试图运行来自不同计算机的过程中,并且将所得的下列(该程序在Master2008 beeing运行):
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岁多的问题似乎有点多余。计算机已经在AD中标记为可信,并不是问题。 – Avilan 2013-12-19 11:24:01