27

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:\etc\desktop\file.spp C\etc\desktop\file.txt"

This launches a program with a certain project file and a .txt file along with it.

Donut
  • 110,061
  • 20
  • 134
  • 146
mark
  • 371
  • 2
  • 6
  • 10
  • 1
    I don't understand. All known desktop OS allow you to launch programs and pass command line arguments. Please, what is your question? – David Heffernan Mar 02 '11 at 14:16

3 Answers3

57

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);
Paolo Falabella
  • 24,914
  • 3
  • 72
  • 86
1

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!

fretje
  • 8,322
  • 2
  • 49
  • 61
0

if you want to pass full executable path and parameters the program you need is the windows command prompt.

Davide Piras
  • 43,984
  • 10
  • 98
  • 147
  • 1
    oh i'm sorry, seemed to have left out a big piece of information(sorry). i need this program to prompt the user, asking what files they want to pass as parameters, then actually putting it into the command line – mark Mar 02 '11 at 14:17