1


I am trying to launch the default application registered for an extension specifying an additional argument:

 ProcessStartInfo p = new ProcessStartInfo();
 p.Arguments = "myargument";
 p.FileName = "file.ext";
 Process.Start(p);

The application starts correctly opening the specified file. The problem is that it is getting just one parameter (the name of the file), totally ignoring the additional "Arguments".
Is it possible to do what I want? Am I doing something wrong?

Thanks in advance for any help,
Paolo

Paull
  • 1,020
  • 1
  • 12
  • 21

3 Answers3

1

I believe this is expected. Behind the scenes, Windows is finding the default application in the registry and creating a new process and passing your file name to it. I get the same behavior if I go to a command prompt and type "filename.ext argument", that my arguments are not passed to the application.

What you probably need to do is find the default application yourself by looking in the registry. Then you can start that process with arguments, instead of trying to start by filetype association. There is an answer here on how to find the default application in the registry:

Finding the default application for opening a particular file type on Windows

Community
  • 1
  • 1
irritate
  • 7,350
  • 1
  • 17
  • 11
  • Hi irritate, thanks for your answer! It's so sad I have to switch from these 4 lines to querying registry keys... – Paull Feb 16 '11 at 14:17
0

I think an easier method is using the cmd command

 void LaunchAssociatedProgram(string filename) {
     Process.Start( @"cmd.exe", "/C start "+ filename );
 }

EDIT:

I don't know if it works with arguments, but it is what I was looking for to launch an associated program...

Blau
  • 5,742
  • 1
  • 18
  • 27
-1

what exactly is your "argument", does it have spaces, backslash, etc?

    Process process = new Process();
    process.StartInfo.FileName = @"C:\process.exe";
    process.StartInfo.Arguments = @"-r -d something else";
    process.StartInfo.CreateNoWindow = false;
    process.StartInfo.UseShellExecute = false;
    process.Start();

Is there any reason why you cant start the app, then use the extension and arguments in your arguments?

Ryan
  • 4,443
  • 4
  • 26
  • 26
  • Hi, my argument has no spaces, but my FileName is not an executable like in your sample code. I am trying to open an application via extension association. – Paull Feb 16 '11 at 14:10
  • I have to launch an editor passing the file to edit and an argument for entering a special mode. The idea is that the file extension is always known but the executable location is not. – Paull Feb 16 '11 at 14:27