C:\Test\n4.TestConsole.exe
).File.Exists(path)
returns true
.File.OpenRead(path)
gets me its stream with no problem.Process.Start(path)
throws a System.ComponentModel.Win32Exception
with this message:
The system cannot find the file specified.
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 via Process.Start("cmd", "/k " + exe_path)
.
Try this:
private void button1_Click(object sender, EventArgs e)
{
ProcessStartInfo psi = new ProcessStartInfo();
psi.WorkingDirectory = @"C:\Test";
psi.FileName = "n4.TestConsole.exe";
Process.Start(psi);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With