获取的打开的窗口C#列表 [英] Get the list of opened windows C#

查看:108
本文介绍了获取的打开的窗口C#列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在安装任何应用程序。一般来说,用户被要求安装开始前关闭所有窗口。如果不安装将停止在中间
,并要求用户关闭所有打开的窗口。
有人问我在XXX应用程序中添加代码。当应用程序正在运行,如果用户打开任何其他窗口(例如:资源管理器,浏览器,文字等)
,则该应用程序应该抛出一个窗口,说你已经打开的窗口的列表。
我requerst请你建议我如何在C#中启动

During the installation of any application. Generally the user was asked to close all windows before start of installation. if not the installation will stop at the middle and ask the user to close all opened windows. I was asked to add a code in a XXX application. When application is running and if user opened any other window (ex: Explore, browser, word etc..) then the application should throw a window saying that you have opened the list of windows. I requerst you please suggest me how to start in C#.

推荐答案

测试这样的:

var openWindowProcesses = System.Diagnostics.Process.GetProcesses()
   .Where(p => p.MainWindowHandle != IntPtr.Zero && p.ProcessName != "explorer");



openWindowProcesses 应该包含所有打开的应用程序,他们有一个活跃的主窗口。

The openWindowProcesses should contains all open application which they have an active main window.

我把 p.ProcessName!=资源管理器在哪里,因为表达资源管理器是桌面的主要过程,它不应该被关闭。

I put p.ProcessName != "explorer" in the where expression because the explorer is the main process of the Desktop and it should never be closed.

要看着你可以使用过程中的执行 ManagementEventWatcher 类。请参见这个请。

To watching execution of the processes you can use ManagementEventWatcher class. See this please.

这篇关于获取的打开的窗口C#列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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