0

I am working on a program which works when specific program is currently in focus(user are using it). To get the processes I use GetProcesses(), but it does not return all of the processes. For example, I cant get CREO Parametric processes. Is there are other way for me to approach this problem?

Method I use:

   public string getActiveWindowName()
        {
            try
            {
                var activatedHandle = GetForegroundWindow();

                Process[] processes = Process.GetProcesses();
                foreach (Process clsProcess in processes)
                {
                    
                    if (activatedHandle == clsProcess.MainWindowHandle)
                    {
                        string processName = clsProcess.ProcessName;
                        Debug.WriteLine(processName);
                        return processName;
                    }
                }
            }
            catch { }
            return null;
        }
zhemaitis
  • 11
  • 5
  • How did you determine that it wasn't working as expected? Did you look at each process with your actual eyes or just go by what that code returned? Could it just be that the current foreground window is not the main window for that process? Maybe you should write out the process names outside the `if` statement so you can see all of them and see whether the one you're looking for is included. – John Aug 22 '22 at 05:18
  • Related https://stackoverflow.com/a/54441235/495455 *GetProcesses() gives you the running processes, but not the underlying services which are also shown in WindowsTaskManager.* – Jeremy Thompson Aug 22 '22 at 05:21

0 Answers0