我有这样的代码:
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文件,但是我怎么做呢?
发布于 2015-07-09 20:23:32
我在互联网上搜索了你的问题的解决方案,发现了以下网站: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
在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);发布于 2015-07-09 11:55:40
这个问题很可能是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);
}https://stackoverflow.com/questions/31316395
复制相似问题