views:

126

answers:

1

Hi I would like to be able to sync perforce on my build server from another server programmatically using C# . Server A has the EXE on it. Server B has perforce.

I have admin privileges on both machines.

I would like to use something like

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

I have the computer connection

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

scope.Connect();

I am not able to figure out how to put it all together. Any help would be greatly appreciated. Thank you

A: 

I was able to figure it out:

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"]);

    }
Alos