Calling an exe from another application and passing an argument to it .Net
Calling an exe from another application is always easy in .net.
You need to just add System.diagnostics namespace to your project and choose the properties.
Properties
ProcessStartInfo
Stores information about the process.
FileName
The program or filename you want to run. It can be a file such as "example.txt". It can be a program such as "WINWORD.EXE".
Arguments
Stores the arguments, such as -flags or filename.
CreateNoWindow Allows you to run a command line program silently. It does not flash a console window.
WindowStyle Use this to set windows as hidden.
ProcessWindowStyle.Hidden used often.
UserName WorkingDirectory
Domain These control OS-specific parameters.
For more complex situations, where Windows features are used.
Examples
using System.Diagnostics;
class Program
{
static void Main()
{
// Open the file "example.txt" that is in the same directory as
// your .exe file you are running.
// To call any other exe you need to just specify the path of the exe.
Process.Start("example.txt");
}
}
This example is to call an exe and pass the arguments.
using System.Diagnostics;
class Program
{
static void Main()
{
// A.
// Open specified Word file.
OpenMicrosoftWord(@"C:\Users\Sam\Documents\Gears.docx");
}
///
/// Open specified word document.
///
static void OpenMicrosoftWord(string f)
{
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = "WINWORD.EXE";
startInfo.Arguments = f;
Process.Start(startInfo);
}
}