Error: System cannot find specified file [C#]

Asked

Viewed 2,907 times

1

Win32exception (0x80004005): The system cannot find the file specified in System.Diagnostics.Process.Startwithcreateprocess(Processstartinfo startInfo)

While trying to run a recently published program I came across this error, which refers to an application external to my application, called by the code snippet I mention below:

private void CreatePorts(string command, bool ports)   
{            
   Process p = new Process();        

   p.StartInfo.WorkingDirectory = (Application.StartupPath + @"\com0com");
   p.StartInfo.FileName = @"setupc.exe";
   p.StartInfo.UseShellExecute = false;
   p.StartInfo.RedirectStandardOutput = true;
   p.StartInfo.RedirectStandardInput = true;
   p.StartInfo.LoadUserProfile = true;
   p.StartInfo.Verb = @"runas";
   p.StartInfo.CreateNoWindow = true;                                                
   p.StartInfo.Arguments = " " + command;
   p.Start();
}   

It is certain that the address passed to the parameter WorkingDirectory is correct and that the file mentioned in the parameter FileName exists, so I don’t understand what’s wrong.

  • 1

    Checking if the file exists and if you are allowed to run it?

  • @Leandroangelo is also not about permission, I set it to always open as an administrator. The file exists and has permissions.

  • But where in your code are you checking it?

  • As these are external executable applications, I believed that I would not need to check this internally, since I configured each application individually. But I check if my main application was opened with administrator permissions, in case.

  • And the Application.StartupPath, Have you checked if his path is returning what you expect? is not starting in within the release or debug, where you don’t have the subdirectory com0com?

  • I checked yes. I just start after posting it. I’m pretty sure of the directory in which it is running.

Show 1 more comment

1 answer

3


The solution was to create an environment variable for the process I’ve been trying to execute. In my case: C:\Program Files (x86)\com0com

System → Config. Advanced of the System → Variables of Environment → Add the variable in question to the path

Browser other questions tagged

You are not signed in. Login or sign up in order to post.