Tuesday, December 03, 2019

Hide an application from the taskbar

Hide an application (notepad in this case) from task bar using PowerShell
$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)

Reference(s):
http://stackoverflow.com/questions/7219063/win32-how-to-hide-3rd-party-windows-in-taskbar-by-hwnd

No comments:

Configuring TUN/TAP virtual network interface for use with QEMU on Xubuntu 24.04

Configuring TUN/TAP virtual network interface for use with QEMU on Xubuntu 24.04 I am planning to run qemu-system-ppc to play around QEMU ...