开发者

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. I have found these code examples:

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:

http://msdn.microsoft.co开发者_开发技巧m/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. 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜