进程启动但不显示 window

Process start but don't show the window

我正在尝试打开一个外部可执行文件。我可以使用 System.Diagnostics:

中的 Process class 轻松打开外部可执行文件
Process p = new Process()
p.StartInfo.FileName = processName;
p.Start();

这适用于大多数程序,如浏览器和记事本,创建进程并显示其图形界面。然而,当我尝试打开我想要的程序时,进程启动了(可以在任务管理器中看到它,它甚至需要整个 CPU 核心来处理)但是 GUI window 没有显示.来自 Process.Start 的进程可能会发生什么情况而不显示其 GUI?

作为参考,我要执行的程序是ADOM release 60,当我直接在资源管理器shell 或Powershell 中打开它时,它运行100% 正常。这在控制台和 WindowsForms 应用程序中都是可重现的。

以下是一些没有帮助的其他设置:

p.StartInfo.CreateNoWindow = true; // or false
p.StartInfo.ErrorDialog = false;
p.StartInfo.WindowStyle = /* any of possible values */;
p.StartInfo.UseShellExecute = true; // or false

您需要将 WorkingDirectory 设置为可执行文件所在的根文件夹。

var executablePath = .....;
var p = new Process();
p.StartInfo = new ProcessStartInfo(executablePath);
p.StartInfo.WorkingDirectory = Path.GetDirectoryName(executablePath);
p.Start();

WorkingDirectory的默认值为%SYSTEMROOT%\System32。许多遗留应用程序都有硬编码的相对路径,这些路径解析为所述目录的完整路径,并且在尝试读取(或创建)不应该读取的文件时会失败。