Click here to Skip to main content
15,891,847 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I would like to open an exe file in c#
I use this command: System.Diagnostics.Process.Start("notepad.exe");
The notepad.exe is near my exe file.
My program starts and closes without any error message, but it does not open the notepad.exe
What can be the problem?
Thank you.
Posted
Comments
Marcin Kozub 4-Dec-14 2:49am    
How about sharing your code? We have no access to your hard drive...
sqs1991 4-Dec-14 2:52am    
System.Diagnostics.Process.Start("notepad.exe");
sqs1991 4-Dec-14 3:00am    
I manage to open if the notepad exe is not near my exe, but if the notepad.exe is neear my exe, I can't open the notepad.
TheRealSteveJudge 4-Dec-14 3:03am    
What does "near my exe" mean? Same directory?
syed shanu 4-Dec-14 3:25am    
What is the problem Its working fine for me.
Opening a new Notepad.
private void button1_Click(object sender, EventArgs e)
{
System.Diagnostics.Process.Start("notepad.exe");

}

The most likely reason is that the system can't find the "notepad.exe" file (or one of the assemblies it relies upon): it worked fine on my system - as I expected it would - so it's probable that you are trying to run a "custom" notepad file (and your comment that "The notepad.exe is near my exe file." would back that up).

So, if the application is in the same folder as your startup EXE file, then specify the path absolutely:
C#
string p = Application.StartupPath + "\\" + "notepad.exe";
System.Diagnostics.Process.Start(p);
And it should work - assuming your "notepad.exe" doesn't need any other assemblies which aren't also in the same folder.
 
Share this answer
 
Comments
sqs1991 4-Dec-14 3:18am    
Unfortunately it does not work it does the same as my 'solution'.
OriginalGriff 4-Dec-14 3:48am    
Right - so check the file executes on it's own: browse to your applications folder and double click it. Does it work? If not, then the most likely reason is that it's missing essential DLL files that it expects to be in the same folder.
So look at the folder you got the file from: and run it there to check it works.
If it does, then copy files to your app folder until you find the ones you need.
Your app Process.Start should work then.
Assuming notepad is the default text program, Process.Start(@"c:\myfile.txt") will open the file with the default program.
 
Share this answer
 
Comments
sqs1991 4-Dec-14 3:19am    
I do not want to open a txt file.
I would like to open an exe file, for example the notepad. The exe file is neear my my app exe.
Praveen Kumar Upadhyay 4-Dec-14 3:24am    
what is the meaning of near my app
sqs1991 4-Dec-14 3:34am    
in the same folder

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