Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Launch a file with command line arguments without knowing location of exe?

Tags:

c#

.net

vb.net

Here's the situation: I am trying to launch an application, but the location of the .exe isn't known to me. Now, if the file extension is registered (in Windows), I can do something like:

Process.Start("Sample.xls");

However, I need to pass some command line arguments as well. I couldn't get this to work

   Process p = new Process();
   p.StartInfo.FileName = "Sample.xls";
   p.StartInfo.Arguments = "/r";  // open in read-only mode
   p.Start();

Any suggestions on a mechanism to solve this?

Edit @ aku

My StackOverflow search skills are weak; I did not find that post. Though I generally dislike peering into the registry, that's a great solution. Thanks!

like image 589
Richard Morgan Avatar asked Aug 30 '08 12:08

Richard Morgan


2 Answers

Using my code from this answer you can get command associated with xls extension. Then you can pass this command to Process.Start method.

like image 69
aku Avatar answered Nov 04 '22 03:11

aku


If you query the registry, you can retrieve the data about the registered file type and then call the app directly passing the command line arguments. See Programmatically Checking and Setting File Types for an example of retrieving shell information for a file type.

like image 2
Palgar Avatar answered Nov 04 '22 03:11

Palgar