2

I tried to get the foreground Window and write it in a file. After a few tries, I've only got the task list. Now I discovered this Code, but it won't work for me:

Add-Type @"
  using System;
  using System.Runtime.InteropServices;
  public class Tricks {
    [DllImport("user32.dll")]
    public static extern IntPtr GetForegroundWindow();
}
"@

$a = [tricks]::GetForegroundWindow()

get-process | ? { $_.mainwindowhandle -eq $a } 

Thanks :)

Squashman
  • 13,649
  • 5
  • 27
  • 36
MISO
  • 75
  • 5

1 Answers1

3

The code you have is a Powershell snippet. Save that file as something.ps1 or run it from cmd.exe with this:

powershell something.ps1
Peter Badida
  • 11,310
  • 10
  • 44
  • 90