使用Process.Start运行程序时,它找不到它的资源文件

我有这个代码:

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是一个用于OpenGL图形的应用程序。

问题是,当我单击按钮时,可执行文件会运行,但它无法访问其纹理文件。

有没有人有办法解决吗? 我觉得像在后台加载位图文件,然后运行exe文件,但我怎么能这样做?

我在互联网上搜索了你的问题的解决方案,并找到了这个网站: http : //www.widecodes.com/0HzqUVPWUX/i-am-lauching-an-opengl-program-exe-file-from-visual-基本的,但是最纹理的缺失-什么-是- wrong.html

在C#代码中,它看起来像这样:

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

问题很可能是3dcw.exe正在从它当前的工作目录中查找文件。 使用Process.Start运行应用程序时,该应用程序的当前工作目录将默认为%SYSTEMROOT%\system32 。 该程序可能需要一个不同的目录,很可能是可执行文件所在的目录。

您可以使用以下代码设置进程的工作目录:

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