Skip to content

Instantly share code, notes, and snippets.

@emad-elsaid
Created May 30, 2020 16:21
Show Gist options
  • Save emad-elsaid/2c82ab51d793f205c8b57dec75b6f1c4 to your computer and use it in GitHub Desktop.
Save emad-elsaid/2c82ab51d793f205c8b57dec75b6f1c4 to your computer and use it in GitHub Desktop.
Add-Type @"
using System;
using System.Runtime.InteropServices;
public class Tricks {
[DllImport("user32.dll")]
public static extern IntPtr GetForegroundWindow();
}
"@
while($TRUE)
{
$a = [tricks]::GetForegroundWindow()
get-process | ? { $_.mainwindowhandle -eq $a }
sleep 1
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment