如何将参数传递给exe?

How to pass parameters to an 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 地址,然后是驱动器路径?

你可以在下面post看到它(@AndyMcCluggage 的回答):

How do I start a process from 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]

希望以下代码对您有所帮助。

来自第一个 .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]);
}

右键单击.exe文件-->转到快捷方式-->在目标选项卡中将参数写在最右边... 在我的例子中它起作用了

Step1.Create 快捷方式然后右键单击快捷方式-->单击属性页然后目标选项卡将注释行参数写在最右边...这种方式对我有用