When running a program using Process.Start, it can't find it's resource files

痞子三分冷 提交于 2019-12-20 02:28:11

问题


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 app for OpenGL graphics.

The problem is that when I click on the button, the executable file runs, but it can't access its texture files.

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


回答1:


I've searched on the internet for a solution at 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);



回答2:


The problem is most likely that the 3dcw.exe is looking for files from it's current working directory. When you run an application using Process.Start, the current working directory for that application will default to %SYSTEMROOT%\system32. The program probably expects a different directory, most likely the directory in which the executable file is located.

You can set the working directory for the process using the code below:

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);
}


来源:https://stackoverflow.com/questions/31316395/when-running-a-program-using-process-start-it-cant-find-its-resource-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!