如何在远程计算机上执行命令? [英] How to execute a command in a remote computer?

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

问题描述

我在一台服务器的共享文件夹,我需要一些文件远程执行命令。我怎么做?

I have a shared folder in a server and I need to remotely execute a command on some files. How do I do that?

需要什么服务在服务器上运行,使这项工作?

What services need to be running on the server to make that work?

一些细节:只有C#都可以使用。没有什么可以被安装在服务器

Some details: Only C# can be used. Nothing can be installed in the server.

推荐答案

另一种解决方案是使用 WMI。 NET或Windows管理规范

Another solution is to use WMI.NET or Windows Management Instrumentation.

使用.NET Framework命名空间System.Management,您可以使用Windows Management Instrumentation(WMI)自动执行管理任务。

Using the .NET Framework namespace System.Management, you can automate administrative tasks using Windows Management Instrumentation (WMI).

code样品

var processToRun = new[] { "notepad.exe" };
var connection = new ConnectionOptions();
connection.Username = "username";
connection.Password = "password";
var wmiScope = new ManagementScope(String.Format("\\\\{0}\\root\\cimv2", REMOTE_COMPUTER_NAME), connection);
var wmiProcess = new ManagementClass(wmiScope, new ManagementPath("Win32_Process"), new ObjectGetOptions());
wmiProcess.InvokeMethod("Create", processToRun);

如果您有认证的麻烦,然后检查DCOM配置。

If you have trouble with authentication, then check the DCOM configuration.

  1. 在目标机器上,在命令提示符下运行 DCOMCNFG
  2. 展开组件服务\计算机\我的电脑\ DCOM配置
  3. 找到Windows管理指令,确定了GUID 8BC3F05E-D86B-11D0-A075-00C04FB68820 (你可以看到这个在详细视图)。
  4. 编辑属性,然后添加你想登录的权限选项卡下的用户名。
  5. 您可能需要重新启动该服务或整个计算机。
  1. On the target machine, run dcomcnfg from the command prompt.
  2. Expand Component Services\Computers\My Computer\DCOM Config
  3. Find Windows Management Instruction, identified with GUID 8BC3F05E-D86B-11D0-A075-00C04FB68820 (you can see this in the details view).
  4. Edit the properties and then add the username you are trying to login with under the permissions tab.
  5. You may need to reboot the service or the entire machine.

注意:用于远程过程的所有路径必须是本地到目标机

NOTE: All paths used for the remote process need to be local to the target machine.

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

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