[英]System.Diagnostics.Process from ManagementBaseObject
I'm executing a remote process using WMI and would like to redirect the StandardOutput of that process back to my program. 我正在使用WMI执行远程进程,并希望将该进程的StandardOutput重定向回我的程序。 I have found these code examples: 我发现了以下代码示例:
http://haripotter.wordpress.com/2008/07/25/executing-a-command-on-a-remote-windows-system-using-wmi/ http://haripotter.wordpress.com/2008/07/25/executing-a-command-on-a-remote-windows-system-using-wmi/
That person is using the Process class which I see here: 该人正在使用Process类,我在这里看到:
http://msdn.microsoft.com/en-us/library/ssk42c11.aspx http://msdn.microsoft.com/en-us/library/ssk42c11.aspx
Can redirect standard output. 可以重定向标准输出。 Is it possible to use these two together? 可以同时使用这两个吗?
I am invoking it this way: 我以这种方式调用它:
public string StartProcess(string command)
{
ManagementClass processTask = new ManagementClass(@"\\" + this.wmiConnection.machineName + @"\root\CIMV2", "Win32_Process", null);
ManagementBaseObject methodParams = processTask.GetMethodParameters("Create");
methodParams["CommandLine"] = command;
methodParams["CurrentDirectory"] = @"C:\";
try
{
ManagementBaseObject exitCode = processTask.InvokeMethod("Create", methodParams, null);
I think you're a little confused about this. 我认为您对此有些困惑。 There is not posible mix the Win32_Process
WMI class (or any) and the System.Diagnostics.Process
class, both belong to different scopes. Win32_Process
WMI类(或任何类)和System.Diagnostics.Process
类不可能混合使用,它们都属于不同的作用域。 About your another questions, I think you are out luck here, because with the System.Diagnostics.Process
class you cna redirect the standard output but does not allow execute a remote process, and wiht the Win32_Process
WMI Class you can execute a remote process (with limitations) but does not allow redirect the standard output. 关于另一个问题,我想您很幸运,因为使用System.Diagnostics.Process
类可以重定向标准输出,但不允许执行远程进程,并且使用Win32_Process
WMI类,您可以执行远程进程(有限制),但不允许重定向标准输出。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.