Process.Start does not load executable dependencies

-1

I created a code that opens a program, but the program needs the DLLS / Folders - in the folder it is located, so when I run it from the error, it seems that it is not picking up the DLLS / Folders (if I perform normal, usually the program).

Do I have to use the Stream process instead of FileDialog ?

private void button5_Click(object sender, EventArgs e)
{
    OpenFileDialog openFileDialog1 = new OpenFileDialog();

    openFileDialog1.Filter = "Programa (*.exe)|*.exe";

    if (openFileDialog1.ShowDialog() == DialogResult.OK)
    {
        Process.Start(openFileDialog1.FileName);
    }
}
    
asked by anonymous 23.09.2017 / 14:48

1 answer

0

Let's think about its application as meuapp.exe and the process to be executed with subprocesso.exe .

meuapp.exe is located in C:\vinicius\meuapp.exe and subprocesso.exe is in C:\foo\subprocesso.exe . In addition to subprocesso.exe , the foo folder contains all dependencies of the subprocess, the vital libraries for its execution.

In a simplified way, when you run Process.Start(@"C:\foo\subprocesso.exe") , this file runs as if it were in the root of the caller. In this case, it runs as if it belonged to C:\vinicius .

To solve this problem, we will create an object instance of type ProcessStartInfo and set property WorkingDirectory to C:\subprocesso\ . Instead of using the overload of passing the string path as a parameter of the Process.Start method, I will use ProcessStartInfo which allows us to give some more information for the execution of the process.

ProcessStartInfo paramProcesso = new ProcessStartInfo();
paramProcesso.FileName = "subprocesso.exe";
paramProcesso.WorkingDirectory = @"C:\subprocesso\";
Process.Start(paramProcesso);

In this way, the subprocess execution directory will be the root folder itself, which contains its dependencies (in this case the DLLs).

    
23.09.2017 / 16:26