public static Process GetProcessForActiveApplication()
{
IntPtr activeProcessId;
IntPtr activeWindowHandle = GetForegroundWindow();
GetWindowThreadProcessId(activeWindowHandle, out activeProcessId);
return Process.GetProcessById(activeProcessId.ToInt32());
}