我有一个可执行文件的路径(
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);
}
}
Process.Start(path)
时,path
不是你想象的那样。像Derek已经要求的那样,向我们展示完整的代码,也许我们可以找到问题所在。你是否尝试过调试并确保path
符合你的预期? - Shadow The Spring Wizard