如何获取应用程序的名称? [英] How can I get the name of the applications?

查看:69
本文介绍了如何获取应用程序的名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做一个控制台应用程序,我需要获取正在执行的应用程序的名称,我尝试使用Process.GetProcesses()并使用属性ProcessName执行它,但是有应用程序吗因为Visual Studio出现为"devenv.exe"
与此不一样。我想知道是否可以使用其他方法来获取与应用程序相对应的名称。


谢谢

解决方案

Process.GetProcesses是正确的方法。进程名称是应用程序的实际名称。您所指的可能是应用程序标题栏中显示的标题(主窗口)。这是您在查看任务管理器
或等效项时通常会看到的内容。


要获取流程主窗口的标题,请使用
MainWindowTitle
属性。请注意,并非所有进程都具有主窗口,因此具有标题。对于那些你真正拥有的是进程名称。这是预料之中的。另请注意,您无权访问可能通过该方法返回的所有进程
,因此您需要使用try-catch保护任何进程访问逻辑以防止异常(例如访问系统进程时)。


I'm doing a console application where i'm required to get the name of the applications that are being executed, i tried doing it with Process.GetProcesses() with the attribute ProcessName, but are there applications such as Visual Studio comes out as "devenv.exe" and not the same as such. I wanted to know if it is possible with some other method to obtain the name that corresponds to each if the applications.

Thanks

解决方案

Process.GetProcesses is the correct approach. The process name is the actual name of the app. What you're referring to is perhaps the title seen in the title bar of the application (the main window). This is what you generally see when you look in Task Manager or equivalent.

To get the title of the main window of a process use the MainWindowTitle property. Note that not all processes have a main window and therefore a title. For those all you really have is the process name. This is expected. Also note that you don't have permission to access all the processes that may be returned by the method so you need to protect any process access logic with try-catch to prevent exceptions (such as when accessing system processes).


这篇关于如何获取应用程序的名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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