How to Get Active Process Name in C#?
As mentioned in this answer, you have to use GetWindowThreadProcessId() to get the process id for the window and then you can use the Process: [DllImport(“user32.dll”)] public static extern IntPtr GetWindowThreadProcessId(IntPtr hWnd, out uint ProcessId); [DllImport(“user32.dll”)] private static extern IntPtr GetForegroundWindow(); string GetActiveProcessFileName() { IntPtr hwnd = GetForegroundWindow(); uint pid; GetWindowThreadProcessId(hwnd, out pid); Process p … Read more