- I have the path of an executable file (
C:\Test\n4.TestConsole.exe). File.Exists(path)returnstrue.File.OpenRead(path)gets me its stream with no problem.Process.Start(path)throws aSystem.ComponentModel.Win32Exceptionwith this message:The system cannot find the file specified.
What am I doing wrong?
Windows 8 Professional x64 – .NET Framework 4.5
Edit: Here is the code.
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);
}
}
It’s probably a missing DLL or other dependency. You might like to compare the PATH environment variable when you run it directly via
Process.Start(exe_path)and when you run it viaProcess.Start("cmd", "/k " + exe_path).