2012-01-27 92 views
4

我有以下代碼來作爲圖像中所描述的遠程計算機上從一個共享第二遠程機器上運行的過程:使用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的安裝機器。

有沒有人有任何想法可能是錯誤的?

回答

1

,似乎有與代碼沒有問題。我試圖做一個簡單的應用程序來開始,而不是「calc.exe」,它的工作原理應該如此。

的問題是,我試圖開始從64位服務器「的calc.exe」對32位客戶。另外,Windows7上的「calc.exe」不會在WindowsXP上運行。

0

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

不能使用委派模擬級別,除非所有參與交易的用戶帳戶和計算機帳戶都被標記爲在Active Directory中爲委派信任。這有助於降低安全風險。儘管遠程計算機可以使用您的憑證,但只有當它與交易中涉及的任何其他計算機都可信任才能進行委託時,它纔可以使用憑證。

+2

接聽標記爲解決一個2歲多的問題似乎有點多餘。計算機已經在AD中標記爲可信,並不是問題。 – Avilan 2013-12-19 11:24:01

相關問題