Click here to Skip to main content
16,017,650 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
I want to open an .exe file from button click.

Here is my code:

C#
Process myProcess = new Process();
myProcess.StartInfo.UseShellExecute = false;
myProcess.Start();
StartInfo.FileName = @"C:\Users\MyName\Desktop\NewFolder\Application.exe";


This is not working.
Can anyone please tell me whats wrong.

What I have tried:

Created an application to open an executable file from button click event.
Posted
Updated 19-May-16 18:40pm
Comments
Kornfeld Eliyahu Peter 19-May-16 16:54pm    
For first step study the compile error you got...
Patrice T 19-May-16 19:21pm    
Define 'not working'

try

C#
ProcessStartInfo startInfo = new ProcessStartInfo (@"C:\Users\MyName\Desktop\NewFolder\Application.exe");
           startInfo.UseShellExecute =false;
           Process.Start(startInfo);

or

C#
ProcessStartInfo startInfo = new ProcessStartInfo(@"C:\Users\MyName\Desktop\NewFolder\Application.exe");
Process myProcess = new Process();
myProcess.StartInfo = startInfo;
myProcess.Start();
 
Share this answer
 
You have the wrong order of things and also forgot the variable name in the last statement.
C#
Process myProcess = new Process();
myProcess.StartInfo.UseShellExecute = false;
myProcess.Start();
StartInfo.FileName = @"C:\Users\MyName\Desktop\NewFolder\Application.exe";

should be
C#
Process myProcess = new Process();
myProcess.StartInfo.UseShellExecute = false;
myProcess.StartInfo.FileName = @"C:\Users\MyName\Desktop\NewFolder\Application.exe";
myProcess.Start();
 
Share this answer
 
There is no such concept as "open an EXE". You can open a ".EXE" file file and read its bytes, then close it. I doubt that this is what you want (but I could explain how to do it, only if you explain the purpose of doing so :-)). Or you can simply use the file, which might be the valid application file for the given platform, to start that application. This is how: Process.Start Method (System.Diagnostics)[^].

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900