繁体   English   中英

使用另一个可执行文件的命令行参数启动进程

[英]Start a process with a command line parameter of another executable

我正在尝试通过C#代码将.exe传递给另一个。

到目前为止,这是我的代码:

string ex1 = System.Windows.Forms.Application.StartupPath.ToString() + "\\dev\\psm.exe";
string ex2 = System.Windows.Forms.Application.StartupPath.ToString() + "\\dev\\Application\\app.exe";

ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.CreateNoWindow = false;
startInfo.UseShellExecute = false;
startInfo.FileName = ex1;
startInfo.WindowStyle = ProcessWindowStyle.Normal;
startInfo.Arguments = ex2;

try
{
    Process.Start(startInfo);
}
catch
{
}

将文件拖到应用程序时,哪个参数有效?
细节:
正常运行psm.exe时,它将提示您输入文件名和目录。
运行psm.exe


但是,当您在psm.exe上拖动批准的应用程序时, 使用psm.exe运行文件
它会自动加载应用程序。 正在运行的应用



如何用C#完成?

您可以像这样同步运行另一个应用程序:

System.Diagnostics.Process myapp = new System.Diagnostics.Process();
myapp.StartInfo.FileName = ex1;
myapp.StartInfo.Arguments = ex2;
myapp.Start();
myapp.WaitForExit();

根据您要启动的应用程序期望命令行参数传递的方式,您可能需要以下参数:

myapp.StartInfo.Arguments = String.Format("/MyArgumentName={0}", ex2);

那等于:

c:\MyApplicationStartupPath\dev\psm.exe /MyArgumentName=c:\MyApplicationStartupPath\Application\App.exe

确保匹配app.exe期望StartInfo.Arguments中的参数的方式

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM