5

  • 実行可能ファイルのパスがあります(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);
    }
}
4

2 に答える 2

2

DLLまたはその他の依存関係が欠落している可能性があります。Process.Start(exe_path)を介して直接実行する場合と、を介して実行する場合の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 に答える