Freigeben über


Scripts From TechEd 2012… Part 1 (Keeping PowerShell Window On Top)

I just finished my speaking session at TechEd 2012, once the recording is available I will post a link…  I’ve already had an overwhelming number of requests for the scripts that I used during the session.  I’m going to do a few posts over the next few days, as I can steal 10 min from all the TechEd activities.

 

The first script and the one that every seemed the most interested in keeps a PowerShell Window on top i.e. the top most window.  The way I did it was a bit evil – well very non PowerShell but it works.  I use PInvoke…

 

$signature = @’
[DllImport("user32.dll")]
public static extern bool SetWindowPos(
    IntPtr hWnd,
    IntPtr hWndInsertAfter,
    int X,
    int Y,
    int cx,
    int cy,
    uint uFlags);
‘@
 
$type = Add-Type -MemberDefinition $signature -Name SetWindowPosition -Namespace SetWindowPos -Using System.Text -PassThru

$handle = (Get-Process -id $Global:PID).MainWindowHandle
$alwaysOnTop = New-Object -TypeName System.IntPtr -ArgumentList (-1)
$type::SetWindowPos($handle, $alwaysOnTop, 0, 0, 0, 0, 0x0003)

 

So there you go – look for more of the scripts latter tonight or tomorrow…

 

-taylorb

Comments

  • Anonymous
    February 24, 2016
    The comment has been removed