如何将参数传递给exe?

我在我的服务器上使用psexec在另一台服务器上运行exe文件。 如何将参数传递给其他exe?

我在我的服务器上运行的exe是psexec,而后者必须运行位于另一个系统上的名为vmtoolsd.exe的exe。 如何将参数传递给vmtoolsd.exe? 另外,我在哪里通过它? 我会将它作为info.Arguments的一部分传递给我吗? 我试过了,但它没有用。

ProcessStartInfo info = new ProcessStartInfo(@"C:\Tools"); info.FileName = @"C:\Tools\psexec.exe"; info.Arguments = @"\\" + serverIP + @"C:\Program Files\VMware\VMwareTools\vmtoolsd.exe"; Process.Start(info); 

另外,作为info.Arguments的一部分,我必须在vmtoolsd.exe的路径前加上IP地址,然后是驱动器路径?

希望以下代码可能有所帮助。

第一个.exe的代码:

 Process p= new Process(); p.StartInfo.FileName = "demo.exe"; p.StartInfo.Arguments = "param1 param2"; p.Start(); p.WaitForExit(); or Process.Start("demo.exe", "param1 param2"); 

demo.exe中的代码:

 static void Main (string [] args) { Console.WriteLine(args[0]); Console.WriteLine(args[1]); } 

您可以在以下post中看到它(由@AndyMcCluggage回答):

如何从C#启动进程?

 using System.Diagnostics; ... Process process = new Process(); // Configure the process using the StartInfo properties. process.StartInfo.FileName = "process.exe"; process.StartInfo.Arguments = "-n"; process.StartInfo.WindowStyle = ProcessWindowStyle.Maximized; process.Start(); process.WaitForExit();// Waits here for the process to exit. 

它提供了更多的控制,你可以在MSDN中看到,但基本上参数控制很容易,你可以看到,只是用字符串修改属性。

更新:由于使用上面的代码段代码,您将启动PsExec,基于:

PSEXEC

您必须使用的格式是:

 psexec @run_file [options] command [arguments] 

其中: arguments Arguments to pass (file paths must be absolute paths on the target system)

由于您正在启动的进程是psexec ,因此在process.StartInfo.Arguments您必须将所需的所有参数放在一个@run_file [options] command [arguments]链中: @run_file [options] command [arguments]

右键单击.exe文件 – >转到快捷方式 – >在目标选项卡中写出最右边的争论…在我的情况下它工作了