2010-03-02 60 views
0

嗨我希望能夠使用C#以編程方式從另一臺服務器同步我的構建服務器上的perforce。 服務器A上有EXE。 服務器B有perforce。我需要幫助同步c遠程計算機上的perforce#

我在兩臺機器上都有管理員權限。

我想用類似

System.Diagnostics.Process.Start("p4 sync", "\"" + path + @""" -f //release/production/...") 

我的電腦連接

ManagementScope scope = new ManagementScope("\\\\" + computer_name + "\\root\\cimv2"); 

scope.Connect(); 

我無法弄清楚如何把它放在一起。 任何幫助將不勝感激。謝謝

回答

0

我能弄明白:

public static void perforce_sync() 
    { 

     string computer_name = @"server_name"; 
     ManagementScope scope = new ManagementScope("\\\\" + computer_name + "\\root\\cimv2"); 
     scope.Connect(); 
     ObjectGetOptions object_get_options = new ObjectGetOptions(); 
     ManagementPath management_path = new ManagementPath("Win32_Process"); 
     ManagementClass process_class = new ManagementClass(scope, management_path, object_get_options); 
     ManagementBaseObject inparams = process_class.GetMethodParameters("create"); 
     inparams["CommandLine"] = @"p4 sync -f //release/..."; 
     ManagementBaseObject outparams = process_class.InvokeMethod("Create", inparams, null); 
     Console.WriteLine("Creation of the process returned: " + outparams["returnValue"]); 
     Console.WriteLine("Process ID: " + outparams["processId"]); 

    }