views:

90

answers:

0

I am currently launching a remote process using the following code (in C#):

ConnectionOptions connOptions = new ConnectionOptions();
connOptions.EnablePrivileges = true;
connOptions.Username = userName;
connOptions.Password = password;

ManagementScope manScope = new ManagementScope(String.Format(@"\\{0}\ROOT\CIMV2", remoteMachine), connOptions);
manScope.Connect();

ManagementPath managementPath = new ManagementPath("Win32_Process");
ManagementClass processClass = new ManagementClass(manScope, managementPath, new ObjectGetOptions());
ManagementBaseObject inParams = processClass.GetMethodParameters("Create");
inParams["CommandLine"] = @"C:\MyRemoteProgram.exe";
ManagementBaseObject outParams = processClass.InvokeMethod("Create", inParams, null);

However, I want to redirect the Standard Output and Error messages from that remote process and use them in the launching program. Is there a way to achieve the same? Am I supposed to use Process.GetProcesses(remoteMachine) and use the Process object to hook? Is this the right way?

Thanks in advance.

Ananth