.NET 进程崩溃,但在资源管理器中运行正常

发布于 2024-10-06 09:01:42 字数 1186 浏览 2 评论 0原文

我正在编写一个小程序,它将用作特定游戏引擎的数字分发平台。

该游戏引擎的版本相当旧,这似乎导致了一些兼容性问题。

如果我直接从资源管理器运行一个特定的游戏(即 dbl 单击 exe),运行一个特定的游戏似乎工作正常,但如果我从程序中将它作为一个进程运行,它会立即崩溃。

那么 .NET 中的进程与仅从 shell 运行它有什么区别呢?

这是我当前的代码:(

根据记录,这个版本的引擎不需要 dosbox,所以它不是 dosbox 搞砸了。)

if (Status == "Ready")
                {
                    System.Diagnostics.Process Proc = new System.Diagnostics.Process();
                    if (NeedsDosBox)
                    {
                        Proc.StartInfo.FileName = String.Format("{0}\\dosbox.exe", Globals.AppDir);
                        Proc.StartInfo.Arguments = String.Format("{2}\\{0}\\{1}", GameId, Executable, Globals.Gamecache);
                    }
                    else
                    {
                        Proc.StartInfo.FileName = String.Format("{2}\\{0}\\{1}", GameId, Executable, Globals.Gamecache);
                    }
                    Proc.StartInfo.UseShellExecute = true;
                    Proc.EnableRaisingEvents = true;
                    Proc.Exited += new EventHandler(Proc_Exited);
                    Status = "In Game";
                    Proc.Start();

                }

I'm writing a small program which is to be used as a digital distribution platform for a specific game engine.

This game engine has versions which are quite old and this seems to be causing some compatibility issues.

Running a particular game seems to work fine if i run it directly from explorer (i.e dbl clicking the exe) but if I run it as a process from within my program it crashes out immediately.

So whats the difference between a process in .NET and just running it from the shell?

heres my current code:

(For the record this version of the engine does not need dosbox, so its not dosbox that is screwing up.)

if (Status == "Ready")
                {
                    System.Diagnostics.Process Proc = new System.Diagnostics.Process();
                    if (NeedsDosBox)
                    {
                        Proc.StartInfo.FileName = String.Format("{0}\\dosbox.exe", Globals.AppDir);
                        Proc.StartInfo.Arguments = String.Format("{2}\\{0}\\{1}", GameId, Executable, Globals.Gamecache);
                    }
                    else
                    {
                        Proc.StartInfo.FileName = String.Format("{2}\\{0}\\{1}", GameId, Executable, Globals.Gamecache);
                    }
                    Proc.StartInfo.UseShellExecute = true;
                    Proc.EnableRaisingEvents = true;
                    Proc.Exited += new EventHandler(Proc_Exited);
                    Status = "In Game";
                    Proc.Start();

                }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

杀お生予夺 2024-10-13 09:01:42

我的猜测是该进程需要从特定的工作目录运行。当您在资源管理器中双击运行 EXE 时,工作目录是包含 EXE 的目录。当您从另一个进程生成一个进程时,如果您没有明确指定另一个进程,我相信它的工作目录将从您的进程继承。因此,它可能会在工作目录中查找某些资源并失败,因为它正在与进程的工作目录一起运行。

My guess is that the process needs to be run from a specific working directory. When you run an EXE by double-clicking it in Explorer, the working directory is the directory containing the EXE. When you spawn a process from another process, I believe its working directory will be inherited from your process if you do not explicitly specify another. So it may be looking for some resources in the working directory and failing because it's being run with your process' working directory.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文