Click here to Skip to main content
15,879,096 members
Please Sign up or sign in to vote.
3.83/5 (6 votes)
See more:
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.
Posted
Updated 20-May-11 1:10am
v2
Comments
BobJanova 20-May-11 8:23am    
That appears to be a list of -windows-, not application names. Look at the Win32 API for a way to enumerate top level windows.

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[^]
 
Share this answer
 
Comments
CS2011 20-May-11 12:21pm    
Useful info
Tarun.K.S 20-May-11 13:06pm    
Thanks, it should work now. :)
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;
  }
}
 
Share this answer
 
the simplest way i know is to use automation:

C#
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;
        }


}
 
Share this answer
 
Comments
soox 4-Sep-12 13:23pm    
what is AUW ?
Try This

C#
IEnumerable<Process> processList =
    from p in Process.GetProcesses()
    orderby p.WorkingSet64 descending
    select p;
 
Share this answer
 
Try this

C#
//To get Product name - not necessarily the same as the executeable
            string appName = Application.ProductName;
            MessageBox.Show(appName);
            //To find the name of the executable
            appName = Path.GetFileName(Application.ExecutablePath);
            MessageBox.Show(appName);


Hope this helps
 
Share this answer
 
Process[] RunningProcess=Process.GetProcesses();
List<string> ProcessNames= new List<string>();
foreach(Process EachProcess in RunningProcess)
{
    ProcessNames.Add(EachProcess.ProcessName);
}</string></string>
 
Share this answer
 
Hope this will help you.

String thismodulefilenamestr =
System.IO.Path.GetFileName(System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName);
 
Share this answer
 
C#
foreach (Process p in Process.GetProcesses())
            {
                string procFile;
                try
                {
                    procFile = p.Modules[0].FileName;
                }
                catch (Exception)
                {
                    procFile = "n/a";
                }
                Console.WriteLine(string.Format("Process {0}: {1}", p.ProcessName, procFile));
                
            }
            Console.ReadLine();
 
Share this answer
 
v4
Comments
André Kraak 21-Feb-12 2:54am    
Edited solution:
Added pre tags
also u can try............

static void Main(string[] args)
{
var myID = Process.GetCurrentProcess();
var query = string.Format("SELECT ParentProcessId FROM Win32_Process");// WHERE ProcessId = {0}", myID);
var search = new ManagementObjectSearcher("root\\CIMV2", query);
var results = search.Get().GetEnumerator();
if (!results.MoveNext())
throw new Exception("Huh?");
var queryObj = results.Current;
uint parentId = (uint)queryObj["ParentProcessId"];
var parent = Process.GetProcesses(); //.GetProcessById((int)parentId);
foreach(Process proc in parent){
Console.WriteLine("I was started by {0}", proc);}
Console.ReadLine();
}
 
Share this answer
 
also u want the application name that run in application tab of task manager in c#
foreach (Process p in Process.GetProcesses())
{
if (p.MainWindowTitle.Length > 0)
{
Console.WriteLine(p.MainWindowTitle.ToString());
Console.WriteLine(p.ProcessName.ToString());
Console.WriteLine(p.MainWindowHandle.ToString());
Console.WriteLine(p.PrivateMemorySize64.ToString());
}
}
Console.ReadLine();
 
Share this answer
 
Hi,

I recently used the following code to get the application name.

Check the code once.

C#
public bool IsProcessOpen(string applicationName)
        {
            foreach (Process clsProcess in Process.GetProcesses())
            {
                
                if (clsProcess.ProcessName.Contains(applicationName))
                {
                    //if the process is found to be running then we
                    //return a true
                    return true;
                }
            }
            //otherwise we return a false
            return false;
        }

Thanks
 
Share this answer
 
Try it works

foreach (Process process in Process.GetProcesses())
{
string sWindow = process.MainWindowTitle; //returns window text appearing
//on apps form caption
}


//sandeep
 
Share this answer
 
Comments
Thomas Daniels 26-Dec-12 6:29am    
This is a question from 2011, why do you answer to it? The question is solved already.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900