- 我有一个可执行文件的路径(
C:Testn4.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:Testn4.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 或其他依赖项。当您直接通过 Process.Start(exe_path)
运行 PATH 环境变量时,您可能希望比较它,当您通过 Process.Start("cmd", "/k " + exe_path)
运行它时,您可能希望比较 PATH 环境变量。
试试这个:
private void button1_Click(object sender, EventArgs e)
{
ProcessStartInfo psi = new ProcessStartInfo();
psi.WorkingDirectory = @"C:Test";
psi.FileName = "n4.TestConsole.exe";
Process.Start(psi);
}