【发布时间】:2012-10-31 22:19:55
【问题描述】:
- 我有一个可执行文件的路径 (
C:\Test\n4.TestConsole.exe)。 -
File.Exists(path)返回true。 -
File.OpenRead(path)让我毫无问题地获得它的信息流。 -
Process.Start(path)抛出System.ComponentModel.Win32Exception并带有此消息:系统找不到指定的文件。
Windows 8 Professional x64 - .NET Framework 4.5
编辑:这是代码。
public partial class Form1 : Form
{
public string Path { get; set; }
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
// I put a breakpoint here and verify the Path's value is
// C:\Test\n4.TestConsole.exe.
// File.Exists returns true.
MessageBox.Show(File.Exists(Path));
// File.OpenRead doesn't throw an exception.
using (var stream = File.OpenRead(Path)) { }
// This throws the exception.
Process.Start(Path);
}
}
【问题讨论】:
-
可能是缺少的文件是必需的依赖项,例如一个DLL。 TestConsole.exe 是否从命令提示符运行?
-
显示一些代码。这会有所帮助!
-
好吧,它不起作用,所以代码中可能有问题。我不能只是假设你做对了,它可能非常简单。
-
还有别的问题。也许
path不是您在执行Process.Start(path)时所想的那样。向我们展示 Derek 已经问过的完整代码,也许我们可以找到问题所在。您是否也尝试过调试并确保path是您所期望的? -
您能否在命令提示符下从与 WinForms 应用程序的当前目录相同的目录运行?您是否尝试过运行 cmd /k C:\Test\n4.TestConsole.exe 而不是直接运行?