Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Launch Program with Parameters

Tags:

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.

like image 475
mark Avatar asked Mar 02 '11 14:03

mark


People also ask

How do you start an application with a parameter?

Select More >> Open File Location from within the drop-down menu. Right-click on the first associated application shortcut (repeat the next three steps for all associated application shortcuts). Select Properties from the drop-down menu. Record the parameter value for future use.

How do I run a program from command line arguments?

option. You can test command line arguments by running an executable from the "Command Prompt" in Windows or from the "DOS prompt" in older versions of Windows. You can also use command line arguments in program shortcuts, or when running an application by using Start -> Run.

How do you add a startup parameter?

In the right pane, right-click SQL Server (<instance_name>), and then click Properties. On the Startup Parameters tab, in the Specify a startup parameter box, type the parameter, and then click Add. For example, to start in single-user mode, type -m in the Specify a startup parameter box and then click Add.

How do I run a command line argument in CMD?

A command line argument is simply anything we enter after the executable name, which in the above example is notepad.exe. So for example, if we launched Notepad using the command C:\Windows\System32\notepad.exe /s, then /s would be the command line argument we used.


2 Answers

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); 
like image 74
Paolo Falabella Avatar answered Oct 03 '22 17:10

Paolo Falabella


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!

like image 28
fretje Avatar answered Oct 03 '22 17:10

fretje