识别哪个可执行文件引发运行时错误

发布于 2024-09-05 10:04:16 字数 58 浏览 3 评论 0原文

我有一个程序抛出运行时错误对话框。有没有办法以编程方式检测另一个进程中哪个可执行文件是此对话框的父级?

I have a program that is throwing a run-time error dialog. Is there a way to programmatically detect which executable is the parent of this dialog box from another process?

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

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

发布评论

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

评论(2

偷得浮生 2024-09-12 10:04:16

是的。代码如下(省略错误检查):

HWND hWindow = FindWindow( NULL, windowName );
DWORD processId;
GetWindowTheadProcessId( hWindow, &processId );
HANDLE hProcess = OpenProcess( PROCESS_QUERY_INFORMATION, FALSE, processId );
GetModuleFileNameEx( hProcess, NULL, buffer, BUFFER_SIZE );

如果您不关心旧平台,则 GetProcessImageFileName() 函数优于 GetModuleFileNameEx()。

Yes. The code would be something like this (error checking omitted):

HWND hWindow = FindWindow( NULL, windowName );
DWORD processId;
GetWindowTheadProcessId( hWindow, &processId );
HANDLE hProcess = OpenProcess( PROCESS_QUERY_INFORMATION, FALSE, processId );
GetModuleFileNameEx( hProcess, NULL, buffer, BUFFER_SIZE );

The GetProcessImageFileName() function is preferrable to GetModuleFileNameEx() if you aren't concerned with older platforms.

白色秋天 2024-09-12 10:04:16

更新:您可以使用 从窗口句柄获取进程名称GetWindowModuleFileName

要查找查找句柄,您可以 获取 DesktopWindow,然后枚举这些窗口,直到找到带有错误消息的窗口。

Update: You can get a process name from a window handle using GetWindowModuleFileName

To find the find handle, you could get the DesktopWindow and then enumerate the ones until you find the one with the error message.

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