I need to access the active program and Debug the name of the active program but when I use get proccess Id i get that 64 bit proccess can not be accessed by a 32 bit program error
static void Main(string[] args)
{
while (true)
{
IntPtr hWnd = GetForegroundWindow();
uint procId = 0;
GetWindowThreadProcessId(hWnd, out procId);
var proc = Process.GetProcessById((int)procId);
Debug.WriteLine(proc.MainModule);
//Console.ReadKey();
}
}
[DllImport("user32.dll")]
public static extern IntPtr GetForegroundWindow();
[DllImport("user32.dll", SetLastError = true)]
public static extern uint GetWindowThreadProcessId(IntPtr hWnd, out uint lpdwProcessId);
}