在另一个系统上执行exe时获得异常 [英] getting a exception when execute exe on another system

查看:98
本文介绍了在另一个系统上执行exe时获得异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在另一个系统上运行我的exe时,我收到此异常吗?

任何建议?



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)

推荐答案

你是在Form1.Form1_Load(..)中启动一些外部程序 - 通过ShellExecute方法。并且该程序显然不存在于其他系统上或位于不同的路径中。
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.


异常的原因:您假设某个文件存在于您的特定系统中应该出现在所有系统上。



解决方案:



了解如何操作系统工作,永远不依赖任何文件的存在和预定位置。了解自己代码的所有细节。一切都应该基于一些路径计算。特别是,请看我过去的答案:

如何查找我的程序目录可执行目录),

如何查找我的程序目录当前目录,特殊文件夹)。



硬编码时没有任何情况文件路径可以使用。文件名可以由用户提供,在某些配置文件中定义,等等。在打开文件,流或 StreamReader 之前,您的代码应该检查 System.File.Exists



-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


这篇关于在另一个系统上执行exe时获得异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆