Last active
October 4, 2024 21:38
-
-
Save AfroThundr3007730/9663a9ed913dae4c60ef4ccb17dd4799 to your computer and use it in GitHub Desktop.
Hides a console window (even the new WindowsTerminal.exe)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Adapted from https://stackoverflow.com/a/74976541/4087397 | |
function Hide-ConsoleWindow() { | |
# Import 'ShowWindowAsync' method to properly hide windows | |
Add-Type -Name User32 -Namespace Win32 -MemberDefinition ` | |
'[DllImport("user32.dll")] public static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow);' | |
# Mangle the window title to ensure it's unique and allow us to find it | |
$Host.UI.RawUI.WindowTitle = [Guid]::NewGuid() | |
# Find our process by the mangled window title and hide it | |
[Win32.User32]::ShowWindowAsync( | |
(Get-Process).where{ $_.MainWindowTitle -eq $Host.UI.RawUI.WindowTitle }.MainWindowHandle, 0) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For when you want the terminal actually hidden instead of just minimized. (See: microsoft/terminal#12464)