Skip to content

Instantly share code, notes, and snippets.

@technoscavenger
Created December 4, 2019 01:30
Show Gist options
  • Save technoscavenger/ae530cb3a8899f8f8139f5c024171e51 to your computer and use it in GitHub Desktop.
Save technoscavenger/ae530cb3a8899f8f8139f5c024171e51 to your computer and use it in GitHub Desktop.
Hide an application from the taskbar
$code = @"
[DllImport("user32.dll", SetLastError = true)]
public static extern int GetWindowLong(IntPtr hWnd, int nIndex);
[DllImport("user32.dll")]
public static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);
[DllImport("user32.dll")]
public static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
"@
Add-Type -MemberDefinition $code -Name Win32Util -Namespace System
$WS_VISIBLE = 0x10000000
$WS_EX_TOOLWINDOW = 0x00000080
$WS_EX_APPWINDOW = 0x00040000
$SW_HIDE = 0
$SW_SHOW = 5
$MainWindowHandle = (Get-Process -Name notepad)[0].MainWindowHandle
$style = [System.Win32Util]::GetWindowLong($MainWindowHandle,$GWL_STYLE)
$style = $style -band ( -bNOT ($WS_VISIBLE))
$style = $style -bor $WS_EX_TOOLWINDOW
$style = $style -band ( -bNOT ($WS_EX_APPWINDOW))
[System.Win32Util]::ShowWindow($MainWindowHandle, $SW_HIDE)
[System.Win32Util]::SetWindowLong($MainWindowHandle,$GWL_STYLE, $style)
[System.Win32Util]::ShowWindow($MainWindowHandle, $SW_SHOW)
[System.Win32Util]::ShowWindow($MainWindowHandle, $SW_HIDE)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment