我有以下代码,可以从第二台远程机器上的共享文件夹运行一个进程到另一台远程机器上,如下图所示:
(来源: microsoft.com)
我在我的环境中有5台机器,都在同一个域中。其中3台运行Windows Server 2008R2,一台运行Windows 7,一台运行Windows XP:
当我在WinXP和Win7机器上启动进程时,返回值为8,即“未知错误”,但在Server 2008R2机器上启动进程时则没有问题。
所有机器在AD中都被标记为可信委派。
我试图启动的进程是 \\"machine"\c$\Windows\System32\Calc.exe 我尝试从不同的机器上运行该进程,结果如下(程序正在Master2008上运行):
![Connection](https://istack.dev59.com/jLe2p.webp)
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
当我在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机器安装。
有人知道可能出了什么问题吗?