Running a .exe application from Windows forms

2019-01-25 13:05发布

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

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

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

I'm very new to C#, so can anyone please help me out? Thank you!

3条回答
倾城 Initia
2楼-- · 2019-01-25 13:30

https://msdn.microsoft.com/en-us/library/system.diagnostics.processstartinfo.useshellexecute.aspx

These link will provide you full information about .exe process Info.

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.

查看更多
【Aperson】
3楼-- · 2019-01-25 13:34

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.

查看更多
We Are One
4楼-- · 2019-01-25 13:42

You can try with this code:

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

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

Process.Start(startInfo);
查看更多
登录 后发表回答