Skip to content

Instantly share code, notes, and snippets.

@r4dian
Created August 2, 2019 09:51
Show Gist options
  • Save r4dian/25bb90ee813680703b0e3fdc4036efba to your computer and use it in GitHub Desktop.
Save r4dian/25bb90ee813680703b0e3fdc4036efba to your computer and use it in GitHub Desktop.
Make Sticky Notes Always on Top
$code = @'
[DllImport("user32.dll")]
public static extern IntPtr GetForegroundWindow();
'@
Add-Type $code -Name Utils -Namespace Win32
<#
while(1){
$hwnd = [Win32.Utils]::GetForegroundWindow()
Get-Process |
Where-Object { $_.mainWindowHandle -eq $hwnd } |
Select-Object processName, MainWindowTItle, MainWindowHandle
sleep -Milliseconds 200
}
#>
function Set-TopMost($handle) {
$FnDef = '
[DllImport("user32.dll")]
public static extern bool SetWindowPos(int hWnd, int hAfter, int x, int y, int cx, int cy, uint Flags);
';
$user32 = Add-Type -MemberDefinition $FnDef -Name 'User32' -Namespace 'Win32' -PassThru
$user32::SetWindowPos($handle, -1, 0,0,0,0, 3)
}
$windows = (Get-Process | Where-Object {$_.MainWindowTitle -eq "Sticky Notes"} | Select-Object MainWindowHandle)
Write-Output $windows
ForEach ($window in $windows){
Set-TopMost([int]$window.MainWindowHandle)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment