Error opening application with process.start

2

I have an application that tries to execute with process.start or even directly by cmd of Windows, does not start correctly (the application itself presents an error), but if I go to the folder of it and open the executable, it opens correctly.

Within the application folder, there is only one 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 error is because it does not pull this .ini file, does anyone know of any other way to try to open the application via command prompt or by C #?

    
asked by anonymous 12.04.2016 / 17:33

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 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 located. This is true with the ProcessStartInfo class. .

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