Baruch
Baruch

Reputation: 21498

Error - file not found when it is definitely there

I am trying to run a process with System.Diagnostics.Process.Start(), but am getting the following error:

System.ComponentModel.Win32Exception: The system cannot find the file specified

I double checked the path, and even copied the string to a cmd window, where it ran just fine. What could be the problem?

I am using Win7 64 bit, the program I am trying to run was compiled with mingw64-x64, and I am compiling for .NET 2.0

EDIT
While trying to do the suggested

if (File.Exists(Your EXE)) {
}

I found that removing the flags from the command string solved the problem (I didn't think this was an issue and so didn't mention it before)

How do I run commands with parameters?

Upvotes: 0

Views: 1855

Answers (4)

Yván Ecarri
Yván Ecarri

Reputation: 1739

Use the ProcessStartInfo class and set values to the Arguments property:

http://msdn.microsoft.com/en-us/library/system.diagnostics.processstartinfo.aspx

Upvotes: 0

CloudyMarble
CloudyMarble

Reputation: 37566

Add an if statement like:

if (File.Exists(Your EXE))
{
    // Start the process
} 

Otherwise you can not make sure the Path used is the right one.

Take a look at this answer too, maby it helps

Upvotes: 0

Kugel
Kugel

Reputation: 19814

For arguments use this method. Or overload with ProcessStartInfo.

Upvotes: 1

Spencer Ruport
Spencer Ruport

Reputation: 35107

Windows 7 folder redirection could be the issue.

Basically sometimes when you try to access "C:\program files" it will redirect you to something like "C:\users\username\program files"

I'm looking up some resources for you. I'll let you know when I find something that explains it better than I can.

EDIT:

I find that commands with parameters are a pain in the butt to get working correctly. I usually just resort to writing a batch file and then have C# run that.

Upvotes: 1

Related Questions