无法执行远程进程
Unable to Execute Remote Process
我正在尝试使用 Win32_Process
在远程机器上 运行 一些命令,但我无法让它工作。
这是我首先尝试的:
var processClass = new ManagementClass(@"\server.domain.co.uk\root\cimv2:Win32_Process");
var inParams = processClass.GetMethodParameters("Create");
inParams["CommandLine"] = @"echo. 2>C:\users\user.name\desktop\EmptyFile.txt";
inParams["CurrentDirectory"] = @"C:\windows\system32";
var outParams = processClass.InvokeMethod("Create", inParams, null);
但是没有任何反应。我也在 root\cimv2:Win32_Process
本地尝试 运行ning 这个,但还是没有效果。当调用 notepad.exe
而不是命令行时,我能够让它在本地工作,但这在远程计算机上不起作用。
我怎样才能找出问题所在?
在 outParams
中,这是一个 System.Management.ManagementBaseObject
,我可以看到 ClassPath
包含值 Evaluation timed out
- 这可能是为什么它不是的线索吗?不工作?
阅读本文并运行进行一些测试后,似乎与从 CScript
、these processes cannot be made interactive 开始的测试类似:
You can use Win32_Process.Create to execute a script or application on a remote computer. However, for security reasons, the process cannot be interactive. When Win32_Process.Create is called on the local computer, the process can be interactive.
我还是有点糊涂,因为我上面的代码运行并没有出现在任务管理器中,然而文章接着说:
The remote process has no user interface but it is listed in the Task Manager
无论哪种方式,这都符合我的需要,因为我正在 运行 宁 shell 命令 - 但是值得注意的是,以这种方式执行 cmd 命令需要将它们格式化为:
cmd /c <command-goes-here>
在我的例子中,命令需要从特定位置运行,所以我需要传递:
cmd /c cd <path-to-executable> && <command-goes-here>
我正在尝试使用 Win32_Process
在远程机器上 运行 一些命令,但我无法让它工作。
这是我首先尝试的:
var processClass = new ManagementClass(@"\server.domain.co.uk\root\cimv2:Win32_Process");
var inParams = processClass.GetMethodParameters("Create");
inParams["CommandLine"] = @"echo. 2>C:\users\user.name\desktop\EmptyFile.txt";
inParams["CurrentDirectory"] = @"C:\windows\system32";
var outParams = processClass.InvokeMethod("Create", inParams, null);
但是没有任何反应。我也在 root\cimv2:Win32_Process
本地尝试 运行ning 这个,但还是没有效果。当调用 notepad.exe
而不是命令行时,我能够让它在本地工作,但这在远程计算机上不起作用。
我怎样才能找出问题所在?
在 outParams
中,这是一个 System.Management.ManagementBaseObject
,我可以看到 ClassPath
包含值 Evaluation timed out
- 这可能是为什么它不是的线索吗?不工作?
阅读本文并运行进行一些测试后,似乎与从 CScript
、these processes cannot be made interactive 开始的测试类似:
You can use Win32_Process.Create to execute a script or application on a remote computer. However, for security reasons, the process cannot be interactive. When Win32_Process.Create is called on the local computer, the process can be interactive.
我还是有点糊涂,因为我上面的代码运行并没有出现在任务管理器中,然而文章接着说:
The remote process has no user interface but it is listed in the Task Manager
无论哪种方式,这都符合我的需要,因为我正在 运行 宁 shell 命令 - 但是值得注意的是,以这种方式执行 cmd 命令需要将它们格式化为:
cmd /c <command-goes-here>
在我的例子中,命令需要从特定位置运行,所以我需要传递:
cmd /c cd <path-to-executable> && <command-goes-here>