.NET Process crashes but runs fine from explorer
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 Ga开发者_高级运维me";
Proc.Start();
}
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.
精彩评论