使用参数启动程序

时间:2011-03-02 14:12:07

标签: c# command-line command-line-arguments

如何编写一个非常简单的程序,使用命令行导航到用户Program Files目录中的程序,然后使用参数启动.exe?例如:

  

“C:\ etc \ Program Files \ ProgramFolder \ Program.exe C:\ etc \ desktop \ file.spp C \ etc \ desktop \ file.txt”

这将启动一个包含某个项目文件和.txt文件的程序。

3 个答案:

答案 0 :(得分:44)

您可以使用ProcessStartInfo.Arguments属性指定程序的参数字符串:

ProcessStartInfo startInfo = new ProcessStartInfo();        
startInfo.FileName = @"C:\etc\Program Files\ProgramFolder\Program.exe";
startInfo.Arguments = @"C:\etc\desktop\file.spp C:\etc\desktop\file.txt";
Process.Start(startInfo);

答案 1 :(得分:0)

如果你想传递完整的可执行路径和参数,你需要的程序就是windows命令提示符。

答案 2 :(得分:0)

只需创建一个新文本文件,将其命名为“go.cmd”并将以下内容放在其中:

"C:\etc\Program Files\ProgramFolder\Program.exe C:\etc\desktop\file.spp C\etc\desktop\file.txt"

瞧,你有你的计划!

相关问题