如何在c#中运行应用程序名称? [英] How to get running application name in c#?

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

问题描述



如何使用c#在数组中获取所有正在运行的应用程序名称?



我可以获得所有进程但我希望Windows任务管理器中的应用程序名称 - >应用程序窗口。



先谢谢。

解决方案

由于你想知道运行的应用程序而不是进程,这里有一个讨论:

http://bytes.com/topic/c-sharp/answers/487745-available-applications-taskmanager-not-processess-c [ ^ ]


Reflection 是查找产品名称,公司名称版本信息的最佳方式。



 public static string ProductName 
{
get
{
AssemblyProductAttribute myProduct =
(AssemblyProductAttribute)AssemblyProductAttribute.GetCustomAttribute(Assembly.GetExecutingAssembly(),
typeof(AssemblyProductAttribute));
返回myProduct.Product;
}
}


我知道最简单的方法就是使用自动化:



  private   void  LoadApplicationNames()
{
// 当前桌面
AutomationElement rootElement = AutomationElement.RootElement;
var childs = AUW.Getchildrens(rootElement);

foreach (AutomationElement elemnt in childs)
{
string name = elemnt.Current.Name;
if (!string.IsNullOrWhiteSpace(name))
{
var listboxitem = new ListBoxItem();
listboxitem.Content = name;
// 将AutomationId保存在标记中
listboxitem.Tag = elemnt。 Current.AutomationId;
listBox1.Items.Add(listboxitem);
}
}


/// < span class =code-summarycomment>< 摘要 >
/// 检索AutomationElement下的所有子项
/// < / summary >
/// < param < span class =code-summarycomment> name =parent > list元素。< / param >
/// < 返回 > 所有孩子的< / returns >
public AutomationElementCollection Getchildrens(AutomationElement parent)
{
条件findCondition = new PropertyCondition(AutomationElement.IsControlElementProperty, true );
AutomationElementCollection childrens = parent.FindAll(TreeScope.Children,findCondition);
返回儿童;
}





}


Hi,
How can we get all the running applications name in an array using c#?

I can get all the processes but I want application names in Windows task manager-->Applications window.

Thanks in Advance.

解决方案

Since you want to know the Applications which are running instead of processes, here is one discussion:
http://bytes.com/topic/c-sharp/answers/487745-available-applications-taskmanager-not-processess-c[^]


Reflection is the best way to find out product name,company name version like information.

public static string ProductName
{
 get
 {
  AssemblyProductAttribute myProduct =
                                           (AssemblyProductAttribute)AssemblyProductAttribute.GetCustomAttribute(Assembly.GetExecutingAssembly(),
                   typeof(AssemblyProductAttribute));
              return myProduct.Product;
  }
}


the simplest way i know is to use automation:

private void LoadApplicationNames()
{
    // the current desktop
    AutomationElement rootElement = AutomationElement.RootElement;
    var childs = AUW.Getchildrens(rootElement);

    foreach (AutomationElement elemnt in childs)
    {
        string name = elemnt.Current.Name;
        if (!string.IsNullOrWhiteSpace(name))
        {
            var listboxitem = new ListBoxItem();
            listboxitem.Content = name;
            // save the AutomationId in the tag
            listboxitem.Tag = elemnt.Current.AutomationId;
            listBox1.Items.Add(listboxitem);
        }
    }

 
/// <summary>
/// Retrieves all children under AutomationElement
/// </summary>
/// <param name="parent">The list element.</param>
/// <returns>all childrens </returns>
        public AutomationElementCollection Getchildrens(AutomationElement parent)
        {
            Condition findCondition = new PropertyCondition(AutomationElement.IsControlElementProperty, true);
            AutomationElementCollection childrens = parent.FindAll(TreeScope.Children, findCondition);
            return childrens;
        }



}


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

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