When running a program using Process.Start, it cannot find resource files

I have this code:

private void button1_Click(object sender, EventArgs e)
{
    Process p = new Process();
    p.StartInfo.FileName = "C:/Users/Valy/Desktop/3dcwrelease/3dcw.exe";
    p.Start();
}

      

3dcw.exe

is an OpenGL graphics application.

The problem is, when I click the button, the executable is launched, but it cannot access its texture files.

Does anyone have a solution? I think something like downloading bitmap files in the background and then launching the exe file, but how can I do that?

+3


source to share


2 answers


I searched the internet for a solution to your problem and found this site: http://www.widecodes.com/0HzqUVPWUX/i-am-lauching-an-opengl-program-exe-file-from-visual-basic-but-the -texture-is-missing-what-is-wrong.html

In C # code, it looks something like this:



string exepath = @"C:\Users\Valy\Desktop\3dcwrelease\3dcw.exe";
ProcessStartInfo psi = new ProcessStartInfo();
psi.FileName = exepath;
psi.WorkingDirectory = Path.GetDirectoryName(exepath);
Process.Start(psi);

      

+4


source


The problem is most likely that 3dcw.exe is looking for files from the current working folder. When you start an application using the Process.Start

current working directory for that application, the default will be %SYSTEMROOT%\system32

. The program is probably expecting a different directory, most likely the directory where the executable is located.

You can set the working directory for a process using the following code:



private void button1_Click(object sender, EventArgs e)
{
    string path = "C:/Users/Valy/Desktop/3dcwrelease/3dcw.exe";

    var processStartInfo = new ProcessStartInfo();

    processStartInfo.FileName = path;
    processStartInfo.WorkingDirectory = Path.GetDirectoryName(path);

    Process.Start(processStartInfo);
}

      

+3


source







All Articles