5

  • 我有一个可执行文件 ( C:\Test\n4.TestConsole.exe) 的路径。
  • File.Exists(path)返回true
  • File.OpenRead(path)给我它的流没有问题。
  • Process.Start(path)抛出System.ComponentModel.Win32Exception此消息:

    该系统找不到指定的文件。

我究竟做错了什么?

Windows 8 专业版 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);
    }
}
4

2 回答 2

2

它可能是缺少 DLL 或其他依赖项。您可能想比较 PATH 环境变量,当您直接通过运行它Process.Start(exe_path)时,当您通过运行它时Process.Start("cmd", "/k " + exe_path)

于 2012-11-12T16:12:36.280 回答
1

尝试这个:

private void button1_Click(object sender, EventArgs e)
{
    ProcessStartInfo psi = new ProcessStartInfo();
    psi.WorkingDirectory = @"C:\Test";
    psi.FileName = "n4.TestConsole.exe";
    Process.Start(psi);
}
于 2012-11-12T16:17:00.223 回答