Running a .exe application from Windows Forms
Asked Answered
G

3

8

I have an application that I run on the command prompt as follows:

C:\some_location> "myapplication.exe" headerfile.h

I want to create a Windows Forms application where the user can specify the location of the executable and also the header file so that the Windows Forms application can do this for him/her, and the user wouldn't have to go to the command line and do it.

How can I do this?

Guenna answered 24/7, 2012 at 17:7 Comment(0)
S
31

You need to use the Process class:

Process.Start(@"C:\some_location\myapplication.exe");

For arguments:

ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = @"C:\some_location\myapplication.exe";
startInfo.Arguments = "header.h";
Process.Start(startInfo);

Obviously you can pull these names/arguments from text boxes.

Sharkey answered 24/7, 2012 at 17:9 Comment(2)
Thank you. It was of great help.Guenna
@AbhishekVedamoorthy, you should click the check mark to the left to accept this as the answer to your question.Leonardaleonardi
D
7

You can try with this code:

ProcessStartInfo startInfo = new ProcessStartInfo("yourExecutable.exe");

startInfo.Arguments = "header.h"; // Your arguments

Process.Start(startInfo);
Deglutinate answered 24/7, 2012 at 17:11 Comment(0)
F
0

See ProcessStartInfo.UseShellExecute. This page will provide you with the full information about the .exe process information.

Another way that I used is:

ProcessStartInfo objProcess = new ProcessStartInfo(@"Yours .exe path");
objProcess.UseShellExecute = false;
objProcess.RedirectStandardOutput = true;
Process.Start(objProcess);

And it's working fine.

Frontpage answered 20/7, 2016 at 13:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.