Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Launching an application (.EXE) from C#?

How can I launch an application using C#?

Requirements: Must work on Windows XP and Windows Vista.

I have seen a sample from DinnerNow.net sampler that only works in Windows Vista.

like image 909
rudigrobler Avatar asked Oct 27 '08 14:10

rudigrobler


People also ask

How do I run an exe from command prompt?

Type "start [filename.exe]" into Command Prompt, replacing "filename" with the name of your selected file. Replace "[filename.exe]" with your program's name. This allows you to run your program from the file path.

How can I run an EXE file from my C# code?

FileName = "dcm2jpg.exe"; startInfo. WindowStyle = ProcessWindowStyle. Hidden; startInfo. Arguments = "-f j -o \"" + ex1 + "\" -z 1.0 -s y " + ex2; try { // Start the process with the info we specified. // Call WaitForExit and then the using statement will close.

How do I open an .EXE file?

After you download your desired exe on your Android phone, download and install Inno Setup Extractor from the Google Play Store, use a file browser to locate the exe file, and open that file with the app. Inno Setup Extractor will then extract the exe on your Android phone, and you can check out those files afterward.


2 Answers

Use System.Diagnostics.Process.Start() method.

Check out this article on how to use it.

Process.Start("notepad", "readme.txt");  string winpath = Environment.GetEnvironmentVariable("windir"); string path = System.IO.Path.GetDirectoryName(               System.Windows.Forms.Application.ExecutablePath);  Process.Start(winpath + @"\Microsoft.NET\Framework\v1.0.3705\Installutil.exe", path + "\\MyService.exe"); 
like image 41
Igal Tabachnik Avatar answered Sep 18 '22 23:09

Igal Tabachnik


Here's a snippet of helpful code:

using System.Diagnostics;  // Prepare the process to run ProcessStartInfo start = new ProcessStartInfo(); // Enter in the command line arguments, everything you would enter after the executable name itself start.Arguments = arguments;  // Enter the executable to run, including the complete path start.FileName = ExeName; // Do you want to show a console window? start.WindowStyle = ProcessWindowStyle.Hidden; start.CreateNoWindow = true; int exitCode;   // Run the external process & wait for it to finish using (Process proc = Process.Start(start)) {      proc.WaitForExit();       // Retrieve the app's exit code      exitCode = proc.ExitCode; } 

There is much more you can do with these objects, you should read the documentation: ProcessStartInfo, Process.

like image 99
sfuqua Avatar answered Sep 22 '22 23:09

sfuqua