Launch Program with Parameters
How do I write a very simple program that uses the command line to navigate to a program in the user's Program Files directory, then launches the .exe
with a parameter? For example:
"C:\etc\Program Files\ProgramFolder\Program.exe C:\e开发者_JS百科tc\desktop\file.spp C\etc\desktop\file.txt"
This launches a program with a certain project file and a .txt
file along with it.
You can use the ProcessStartInfo.Arguments property to specify the string of arguments for your program:
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);
Just create a new text file, name it "go.cmd" and put the following in there:
"C:\etc\Program Files\ProgramFolder\Program.exe C:\etc\desktop\file.spp C\etc\desktop\file.txt"
Voila, you have your program!
if you want to pass full executable path and parameters the program you need is the windows command prompt.
精彩评论