远程计算机上运行命令 [英] Run command on remote computer

查看:162
本文介绍了远程计算机上运行命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要使用C#在远程计算机上运行命令提示符下的命令。每此链接如何在远程计算机上执行命令?,我试图做到这一点使用下面的代码:

I want to run a command in command prompt on a remote computer using C#. Per this link How to execute a command in a remote computer?, I am trying to do this using the following code:

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,没有错误抛出,但没有什么是执行。请帮助。

This returns an exit code of 0 and no errors are thrown, yet nothing is executed. Please help.

推荐答案

希望这将有助于

http://www.petri.co.il /command-line-wmi-part-2.htm

看一看到备用凭证一节。我相信你是能够做自己的小修改。

Have a look into "Alternate Credentials" section. i believe you are able to do the little modification yourself.

这篇关于远程计算机上运行命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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