Running a .exe application from Windows Forms

帅比萌擦擦* 提交于 2019-11-28 00:28:03

问题


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?


回答1:


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.




回答2:


You can try with this code:

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

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

Process.Start(startInfo);



回答3:


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.



来源:https://stackoverflow.com/questions/11635856/running-a-exe-application-from-windows-forms

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!