Error opening application with process.start

Asked

Viewed 1,203 times

2

I have an app that when trying to run with the process.start or even direct by cmd from Windows, does not start properly (the application itself shows error), but if I go in its folder and open the executable, it opens correctly.

Inside the application folder, there is only it and a parameter file .ini, I’m using the following code:

private void button_abrirr_Click(object sender, EventArgs e)
    {
        try {
            Process.Start(@"C:\Program Files (x86)\IntegradorTEF-IP\IntegradorTEF-IP.exe");
        }
        catch (Exception error)
        {
            MessageBox.Show("Falha ao abrir arquivo!\n\n");
        }
    }

I believe that maybe the mistake is because it does not pull this file .ini, someone knows some other way to try to open the application via prompt command or C#?

  • Post your code as you are calling Process.Start(), it may be an error in the path.

  • I edited the question, but the way is correct, since it tries to open the application and the error message that occurs is from the application itself opened. Other applications are opening normally, usually it’s these apps with . ini files that don’t work.

  • What is "going in the folder"? because by cmd you must be going in the folder. It doesn’t make much sense to run on Windows/File Explore and not work on cmd.

  • Is to open the folder where is located the application and open it with double click of the same mouse. By CMD I put the path, it opens but the application informs error.

1 answer

2


Apparently the executable only works if it is called in the folder where it is, which is a failure, but to resolve this you should call it in the folder instead of the absolute path. For this you need to start the process with more complete information about what will be executed, such as the folder where it is. That’s effect on the class ProcessStartInfo.

var startInfo = new ProcessStartInfo("IntegradorTEF-IP.exe");
startInfo.WorkingDirectory = @"C:\Program Files (x86)\IntegradorTEF-IP";
Process.Start(startInfo);

I put in the Github for future reference.

  • worked perfectly, thank you!

  • vlw the tip, already marked here!

Browser other questions tagged

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