Skip to content

Instantly share code, notes, and snippets.

@benabrahamson
Last active September 4, 2019 20:00
Show Gist options
  • Save benabrahamson/2c6fb4d54907658bf99b137214527434 to your computer and use it in GitHub Desktop.
Save benabrahamson/2c6fb4d54907658bf99b137214527434 to your computer and use it in GitHub Desktop.
Adapted from a script by Peter Hinchley (https://hinchley.net/)
$newtitle = "PRIVATE"
$interval = 10 #milliseconds
Add-Type -TypeDefinition @"
using System;
using System.Runtime.InteropServices;
public static class Win32 {
[DllImport("User32.dll", EntryPoint="SetWindowText")]
public static extern int SetWindowText(IntPtr hWnd, string strTitle);
}
"@
$timer = New-Object System.Timers.Timer
$timer.Enabled = $true
$timer.Interval = $interval
$timer.AutoReset = $true
function Change-Window-Titles($newtitle) {
Get-Process | ? {$_.mainWindowTitle -and $_.mainWindowTitle -notlike "$($newtitle)*"} | %{
[Win32]::SetWindowText($_.mainWindowHandle, "$newtitle")
}
}
Register-ObjectEvent -InputObject $timer -EventName Elapsed -Action {
Change-Window-Titles $newtitle
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment