gpt4 book ai didi

c# - 在远程计算机上运行命令

转载 作者:太空宇宙 更新时间:2023-11-03 13:40:49 25 4
gpt4 key购买 nike

我想使用 C# 在远程计算机上的命令提示符下运行命令。通过此链接 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

查看“备用凭据”部分。我相信您可以自己做一些小改动。

关于c# - 在远程计算机上运行命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17099074/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com