To begin with, we will define the terms in this context, using the example of the Google Chrome browser.

Process name: chrome .exe
enter image description here

Application Name: Google Chrome (32 bit)

I need to know exactly the name of the application, since it is almost always different.

  • Need to know your application name? - Mstislav Pavlov
  • @Bezarius, ideally anybody at all, but answering your question is no, not mine. - anweledig
  • And as I understand it, you want to use the process name as an identifier for the desired application, right? - Mstislav Pavlov
  • @Bezarius, yes, this is a good option. - anweledig

1 answer 1

Take this example as a basis:

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Management; using System.Diagnostics; using System.Management.Instrumentation; namespace getAllProcessID { class Program { 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"]; 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(); } } } 
  • I did not see the MainWindowHandle property, thanks a lot) - anweledig