Process.Start does not load executable dependencies

Asked

Viewed 78 times

-1

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

Do I have to use the process Stream 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);
    }
}

1 answer

0


Let’s think of your application as meuapp.exe and the process to be carried out subprocesso.exe.

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

Simply put, when you spin Process.Start(@"C:\foo\subprocesso.exe"), this file runs as if it were on the root of the caller. In this case, it runs as if it belonged to the C:\vinicius.

To solve this problem, let’s create an object instance of the type ProcessStartInfo and set the property WorkingDirectory for C:\subprocesso\. Instead of using the Overload to pass the string path as the method parameter Process.Start, I’ll use the 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);

This way, the subprocess’s execution directory will be its own root folder, which contains its dependencies (in your case the Dlls).

  • I got it thanks, I just wanted to +1 thing, open the CMD in the case, and execute the Ipconfig command when it opens.

  • @Vinicius https://stackoverflow.com/a/12779667/6241184

Browser other questions tagged

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