检测外部进程是否是交互式的并且具有任何可见的UI [英] Detect if external process is interactive and has any visible UI

查看:56
本文介绍了检测外部进程是否是交互式的并且具有任何可见的UI的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎无法找到一种方法来确定进程是否具有用户界面,例如一个对用户可见的窗口?

I cannot seem to find a way to determine whether a Process has a user interface e.g. a window, which is visible to the user?

  • Environment.UserInteractive is not useful for external processes
  • process.MainWindowHandle != IntPtr.Zero appears to always return false in my tests?

我想区分记事本和conhost

推荐答案


  1. 从您的中查找进程ID。处理实例。

  2. 使用 EnumWindows 枚举顶级窗口。

  3. 调用 GetWindowThreadProcessId 并查看其是否与目标PID匹配。

  4. 调用 IsWindowVisible 和/或 IsIconic 来测试该窗口是否对用户可见。

  1. Find out the process ID from your Process instance.
  2. Enumerate the top-level windows with EnumWindows.
  3. Call GetWindowThreadProcessId and see if it matches the target PID.
  4. Call IsWindowVisible and/or IsIconic to test if that window is visible to the user.

这篇关于检测外部进程是否是交互式的并且具有任何可见的UI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆