Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am getting this exception when i run my exe on another system?
any suggestion?

Exception Text 
System.ComponentModel.Win32Exception (0x80004005): The system cannot find the file specified
   at System.Diagnostics.Process.StartWithShellExecuteEx(ProcessStartInfo startInfo)
   at System.Diagnostics.Process.Start()
   at EMSAlpha1.Form1.Form1_Load(Object sender, EventArgs e)
   at System.Windows.Forms.Form.OnLoad(EventArgs e)
   at System.Windows.Forms.Form.OnCreateControl()
   at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
   at System.Windows.Forms.Control.CreateControl()
   at System.Windows.Forms.Control.WmShowWindow(Message& m)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
   at System.Windows.Forms.Form.WmShowWindow(Message& m)
   at System.Windows.Forms.Form.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
Posted
Updated 18-Mar-15 1:29am
v2

You're starting some external program in your Form1.Form1_Load(..)-Method via ShellExecute. And that program apparently doesn't exist on the other system or is located in a different path.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 18-Mar-15 7:33am    
5ed. Please see also my a bit more detailed answer.
—SA
[no name] 18-Mar-15 7:44am    
Thank you, Sergey!
это приемлемо, если я обращаюсь к вам, только с вашим именем?
- Себастьян
Sergey Alexandrovich Kryukov 18-Mar-15 7:54am    
You are welcome.
Sure, good enough (especially in English :-). I'm often called "SA", this is perfectly fine.
—SA
[no name] 18-Mar-15 7:57am    
Alright :-) I spotted a comment from you which made me think about russian naming conventions again ;-)
Sergey Alexandrovich Kryukov 18-Mar-15 8:29am    
Perhaps it was using full name in low-case, which is very inappropriate in many cultures...
—SA
The reason for the exception: you make false assumption that some file which exists on your particular system should be present on all systems.

Solution:

Learn how OS works and never rely on existence and predefined locations of any files. Know all ins and outs of your own code. Everything should be based on some path calculations. In particular, please see my past answers:
How to find my programs directory (executable directory),
How to find my programs directory (current directory, "special folders").

There are no cases when hard-coded file path can be used. File names can be supplied be the users, defined in some configuration files, and so on. Your code should check up System.File.Exists before opening a file, stream or StreamReader.

—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