我想使用 C# 在远程计算机上的命令提示符中运行命令。根据此链接如何在远程计算机上执行命令? https://stackoverflow.com/questions/428276/how-to-execute-a-command-in-a-remote-computer,我尝试使用以下代码来执行此操作:
public static void RunRemoteCommand(string command, string RemoteMachineName)
{
ManagementScope WMIscope = new ManagementScope(
String.Format("\\\\{0}\\root\\cimv2", RemoteMachineName));
WMIscope.Connect();
ManagementClass WMIprocess = new ManagementClass(
WMIscope, new ManagementPath("Win32_Process"), new ObjectGetOptions());
object[] process = { command };
object result = WMIprocess.InvokeMethod("Create", process);
Log.Comment("Creation of process returned: " + result);
}
这将返回退出代码 0,并且不会引发任何错误,但不会执行任何操作。请帮忙。
希望这会有所帮助
http://www.petri.co.il/command-line-wmi-part-2.htm http://www.petri.co.il/command-line-wmi-part-2.htm
查看“备用凭证”部分。我相信你可以自己做一些小小的修改。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)