c# - 如何将参数传递给exe?

标签 c# psexec process.start

我在我的服务器上使用 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]);
}

关于c# - 如何将参数传递给exe?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29728896/

相关文章:

c# - Process.Start cmd.exe 不会运行在 IIS 中运行时作为参数传递的 cmd 文件

c# - 进程从两个字符串开始

c# - 保存单个实体而不是整个上下文

c# - 如何在运行时增加 byte[] 大小?

c# - 实现接口(interface)的抽象基类

c# - 尝试使用 psexec (c#) 在远程运行 .exe 时出现问题?

ant - 通过 psexec 在 cmd 中运行多个命令

text - 以编程方式在 C# 中打开文本文件

c# - VS2010 将隐式变量显示为类型 'var' 而不是实际类型

powershell - 是否可以通过 Powershell 远程处理以 "nt authority\system"启动进程?