kjagiello
kjagiello

Reputation: 8410

Run external application with no .exe extension

I know how to run an external application in C# System.Diagnostics.Process.Start(executableName); but what if the application I want to run has extension that is not recognizable by Windows as extension of an executable. In my case it is application.bin.

Upvotes: 17

Views: 9089

Answers (2)

mdb
mdb

Reputation: 52829

Key is to set the Process.StartInfo.UseShellExecute property to false prior to starting the process, e.g.:

System.Diagnostics.Process p = new System.Diagnostics.Process();
p.StartInfo.FileName = @"c:\tmp\test.bin";
p.StartInfo.UseShellExecute  = false;
p.Start();

This will start the process directly: instead of going through the "let's try to figure out the executable for the specified file extension" shell logic, the file will be considered to be executable itself.

Another syntax to achieve the same result might be:

var processStartInfo = new ProcessStartInfo
{
    FileName = @"c:\tmp\test.bin",
    UseShellExecute = false
};
Process.Start(processStartInfo);

Upvotes: 31

Steven de Salas
Steven de Salas

Reputation: 21467

And to follow on from @yelnic. Try using cmd.exe /C myapp, I found it quite useful when I want a little more out of Process.Start().

using (Process process = Process.Start("cmd.exe") 
{
   // `cmd` variable can contain your executable without an `exe` extension
   process.Arguments = String.Format("/C \"{0} {1}\"", cmd, String.Join(" ", args));
   process.UseShellExecute  = false;
   process.RedirectStandardOutput = true;
   process.Start();
   process.WaitForExit();
   output = process.StandardOutput.ReadToEnd();
}

Upvotes: 3

Related Questions