The code snippet cuz 2 long
if (-not ("TitleBarPresent.NativeMethods" -as [type])) {
$TitleBarPresent = Add-Type -TypeDefinition @"
using System;
using System.Runtime.InteropServices;
public class TitleBarPresent {
[DllImport("user32.dll", EntryPoint = "GetWindowLongPtr", SetLastError = true)]
private static extern IntPtr GetWindowLongPtr(IntPtr hWnd, int nIndex);
[DllImport("user32.dll", EntryPoint = "GetWindowLong", SetLastError = true)]
private static extern int GetWindowLong(IntPtr hWnd, int nIndex);
[DllImport("user32.dll")]
public static extern IntPtr GetForegroundWindow();
public static bool HasCaption(IntPtr hWnd) {
long style = (IntPtr.Size == 8) ? (long)GetWindowLongPtr(hWnd, -16) : (long)GetWindowLong(hWnd, -16);
long WS_CAPTION = 0x00C00000L;
return (style & WS_CAPTION) == WS_CAPTION;
}
}
"@ -PassThru
}
$hWnd = $TitleBarPresent::GetForegroundWindow()
$hasCaption = $TitleBarPresent::HasCaption($hWnd)
$user = "$env:username@$env:computername"
$adminPrefix = if ($isAdmin) { "[ADMIN] " } else { "" }
$pwshWindowTitle ="$adminPrefix$user"
$Host.UI.RawUI.WindowTitle = switch ($hasCaption) {
$false { "Quake Mode - $pwshWindowTitle" }
$true { $pwshWindowTitle }
default { $pwshWindowTitle }
}
if ($false -eq $hasCaption) {
Set-Location ~
}
The Set-Location bit is a workaround for the Quake mode window to not start in system32