WMIC MangementClass RemoteCommand - 确定何时完成?标准输出? [英] WMIC MangementClass RemoteCommand - determining when it is finished? STDOUT?

查看:34
本文介绍了WMIC MangementClass RemoteCommand - 确定何时完成?标准输出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在通过 WMIC 执行远程 CMD 行命令,该命令需要几秒钟才能运行.在继续之前,我目前正在做 Thread.Sleep(4000) ......必须有更好的方法!是否有一个变量或方法可以用来确定我发出的命令是否完成/状态字节?

I'm executing a remote CMD line command via WMIC that takes a few seconds to run. I'm currently doing Thread.Sleep(4000) before moving on...there MUST be a better way! Is there a variable or method I can use to determine if the command I issued finished / a status byte?

谢谢!

我使用以下代码发出命令:

Im using the following code to issue the commands:

ManagementClass processTask = new ManagementClass(@"\\" + this.wmiConnection.machineName + @"\root\CIMV2", "Win32_Process", null);
        ManagementBaseObject methodParams = processTask.GetMethodParameters("Create");
        methodParams["CommandLine"] = command;
        methodParams["CurrentDirectory"] = @"C:\";

只需要弄清楚如何确定命令何时完成:).谢谢!

Just need to figure out how to determine when the command finishes :). Thanks!

推荐答案

据我所知,当你写这个时:

In my understanding, when you write this :

ManagementClass processTask = new ManagementClass(@"\\192.168.183.100\root\CIMV2", "Win32_Process", null);
ManagementBaseObject methodParams = processTask.GetMethodParameters("Create");
methodParams["CommandLine"] = "cmd.exe";
methodParams["CurrentDirectory"] = @"C:\";

//Execute the method
ManagementBaseObject outParams = processTask.InvokeMethod("Create", methodParams, null);

您以同步方式启动远程进程,所以

You are launching the remote process in a synchronous way, so

outParams["returnvalue"]
outParams["processid"]

将给出返回代码和 processId,如 如何:执行方法,如果你想异步运行它,你可以阅读:如何:异步调用方法.

Will give the return code and processId as explain in How To: Execute a Method, if you want to run it asynchronously you can read this : How To: Call a Method Asynchronously.

这篇关于WMIC MangementClass RemoteCommand - 确定何时完成?标准输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆