检测外部进程是否是交互式的并且具有任何可见的UI [英] Detect if external process is interactive and has any visible UI
本文介绍了检测外部进程是否是交互式的并且具有任何可见的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
对外部进程无用 -
process.MainWindowHandle!= IntPtr.Zero
在我的测试中似乎总是返回false?
Environment.UserInteractive
is not useful for external processesprocess.MainWindowHandle != IntPtr.Zero
appears to always return false in my tests?
我想区分记事本和conhost
推荐答案
- 从您的
中查找进程ID。处理
实例。 - 使用
EnumWindows
枚举顶级窗口。 - 调用
GetWindowThreadProcessId
并查看其是否与目标PID匹配。 - 调用
IsWindowVisible
和/或IsIconic
来测试该窗口是否对用户可见。
- Find out the process ID from your
Process
instance. - Enumerate the top-level windows with
EnumWindows
. - Call
GetWindowThreadProcessId
and see if it matches the target PID. - Call
IsWindowVisible
and/orIsIconic
to test if that window is visible to the user.
这篇关于检测外部进程是否是交互式的并且具有任何可见的UI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文