Reputation: 75
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 :)
Upvotes: 2
Views: 890
Reputation: 12159
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
Upvotes: 3