Home > Software design >  Powershell always-on-top script
Powershell always-on-top script

Time:08-12

I tried this script :

https://github.com/bkfarnsworth/Always-On-Top-PS-Script

It listed all apps successfully, but I doens't seem to actually make a window on top (I selected a notepad window).

CodePudding user response:

FYI there exists a standard Always on Top utility in Microsoft PowerToys that can do this.
Anyways, if you need to automate this, you can do this from PowerShell using the SetWindowPos function (winuser.h) where the second argument (-1) stands for TOPMOST:

$User32 = Add-Type -Debug:$False -MemberDefinition '
    [DllImport("user32.dll")] public static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X,int Y, int cx, int cy, uint uFlags);
' -Name "User32Functions" -namespace User32Functions -PassThru

$Handle = (Get-Process -Name notepad).MainWindowHandle
[Void]$User32::SetWindowPos($Handle, -1, 0, 0, 0, 0, 0x53)
  • Related