获取正在运行的当前APPLICATIONS列表,而不是处理C# [英] Getting a list of current APPLICATIONS running, not processes c#

查看:61
本文介绍了获取正在运行的当前APPLICATIONS列表,而不是处理C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道您可以通过使用 Process []进程= Process.GetProcesses(); Process []进程= Process.GetProcessesByName("processName");

I know you can get a list of the current processes that are running by using Process[] processes = Process.GetProcesses(); or Process[] processes = Process.GetProcessesByName("processName");

但是,我需要获取正在运行的当前应用程序,不一定需要特定的进程.原因是因为有时某些后台运行的进程与某个应用程序相关,但是实际的应用程序本身并未运行.但是出于我的目的,我需要知道实际的应用程序本身是否正在运行.

However I need to grab the current applications that are running, not necessarily the specific processes. The reason is because sometimes there are processes that run in the background that relate to a certain application however the actual application itself is not running. But for my purposes I need to know if the actual application itself is running.

在C#中有没有办法做到这一点?

Is there a way to do this in C#?

显然我还没有说清楚.例如,在任务管理器中,您可以看到当前正在运行的应用程序列表以及当前正在运行的进程列表.我试图获取一个可以在任务管理器中看到的应用程序列表,而不是大量的进程列表

Apparently I haven't made myself clear. For example in Task Manager you can see a list of Applications that are currently running, as well as a list of Processes that are currently running. I'm trying to grab the list of Applications that one can see in Task Manager, not the extensive list of processes

推荐答案

获取进程列表,然后按具有

Get the list of processes, then filter by those processes that have a MainWindowHandle.

仅当过程具有图形界面时,该过程才具有与之关联的主窗口.如果关联的进程没有主窗口,则MainWindowHandle值为零.对于已隐藏的进程,即在任务栏中不可见的进程,该值也为零.对于在任务栏最右侧的通知区域中显示为图标的进程,可能是这种情况.

A process has a main window associated with it only if the process has a graphical interface. If the associated process does not have a main window, the MainWindowHandle value is zero. The value is also zero for processes that have been hidden, that is, processes that are not visible in the taskbar. This can be the case for processes that appear as icons in the notification area, at the far right of the taskbar.

如果它有一个主窗口,就任务管理器而言,它是一个应用程序".

If it has a main window, it's an "application" as far as the Task Manager is concerned.

var processes = Process.GetProcesses()
    .Where(p=> p.MainWindowHandle != 0)
    .ToArray();

这篇关于获取正在运行的当前APPLICATIONS列表,而不是处理C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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