Running exe from c # code

I have a link to an exe file in my C # project. How to call this exe from my code?

+125
c #
Mar 13 2018-12-12T00:
source share
5 answers
using System.Diagnostics; class Program { static void Main() { Process.Start("C:\\"); } } 

If your application needs cmd arguments, use something like this:

 using System.Diagnostics; class Program { static void Main() { LaunchCommandLineApp(); } /// <summary> /// Launch the application with some options set. /// </summary> static void LaunchCommandLineApp() { // For the example const string ex1 = "C:\\"; const string ex2 = "C:\\Dir"; // Use ProcessStartInfo class ProcessStartInfo startInfo = new ProcessStartInfo(); startInfo.CreateNoWindow = false; startInfo.UseShellExecute = false; startInfo.FileName = "dcm2jpg.exe"; startInfo.WindowStyle = ProcessWindowStyle.Hidden; startInfo.Arguments = "-fj -o \"" + ex1 + "\" -z 1.0 -sy " + ex2; try { // Start the process with the info we specified. // Call WaitForExit and then the using statement will close. using (Process exeProcess = Process.Start(startInfo)) { exeProcess.WaitForExit(); } } catch { // Log error. } } } 
+233
Mar 13 '12 at 7:00
source share

+16
Mar 13 '12 at 6:40
source share

Example:

 System.Diagnostics.Process.Start("mspaint.exe"); 

Code compilation

Copy the code and paste it into the Main console application method. Replace "mspaint.exe" with the path to the application you want to run.

+5
Dec 18 '14 at 22:53
source share

Example:

 Process process = Process.Start(@"Data\myApp.exe"); int id = process.Id; Process tempProc = Process.GetProcessById(id); this.Visible = false; tempProc.WaitForExit(); this.Visible = true; 
+4
Oct 13 '16 at 11:12
source share

I know that they answered well, but if you're interested, I wrote a library that makes executing commands a lot easier.

Check it out here: https://github.com/twitchax/Sheller .

0
Feb 19 '19 at 8:44
source share



All Articles