从命令行运行以下命令以在远程计算机上启动进程
wmic /node:remotemachine /user:localadmin process call create "cmd.exe /c C:\temp\myfolder\test.bat"
基本上只是
echo Some Text > output.txt
我通过双击批处理文件进行了测试,并创建了output.txt文件。
批处理文件只是回显到文件。 我这样做是为了查看它是否真正运行。
cmd进程开始。 我可以在流程中看到它,但是批处理文件从未创建文本文件。
我开始尝试从C#应用程序运行EXE,但是它将为可执行文件创建进程,但是该可执行文件执行的操作从未发生。
因此,我开始测试执行相同操作的其他方式,并且遇到了相同的问题。 它会创建进程,但实际上并没有运行bat或exe。
任何帮助,将不胜感激。
我需要更具体一点
我在C#应用程序中使用以下代码:
public static void ConnectToRemoteClient(string client_machine, string target_exe )
{
var connection = new ConnectionOptions();
object[] theProcessToRun = { target_exe };
var wmiScope = new ManagementScope($@"\\{client_machine}\root\cimv2", connection);
wmiScope.Connect();
using (var managementClass = new ManagementClass(wmiScope, new ManagementPath("Win32_Process"), new ObjectGetOptions()))
{
managementClass.InvokeMethod("Create", theProcessToRun );
}
}
称为:
使用以下语法调用它:
string exe = string.Format(@"cmd.exe /c C:\temp\Myfolder\test.bat");
ConnectToRemoteClient("ClientMachine", exe);
它将启动该过程,并且我看到cmd.exe正在运行,但是test.bat动作从未发生。