foreach (Process process in Process.GetProcessesByName("notepad")) { if (process.Id != Process.GetCurrentProcess().Id) //Excludes the process the code is being run from { foreach (ProcessThread thread in process.Threads) { int HwND = process.MainWindowHandle.ToInt32(); // use the handle however you need } } }