Skip to content

Instantly share code, notes, and snippets.

@PetePriority
Last active February 15, 2024 09:07
Show Gist options
  • Save PetePriority/c283c5d8dd3ee14aaa0951482fea50ad to your computer and use it in GitHub Desktop.
Save PetePriority/c283c5d8dd3ee14aaa0951482fea50ad to your computer and use it in GitHub Desktop.
Hide MS Teams sharing bar
Add-Type -TypeDefinition @"
using System;
using System.Runtime.InteropServices;
public class Win32 {
public const int SW_HIDE = 0;
public const int SW_SHOW = 5;
public const int AFFINITY_NONE = 0x00;
public const int AFFINITY_MONITOR = 0x01;
public const int AFFINITY_EXCLUDE_FROM_CAPTURE = 0x11;
[DllImport("user32.dll")]
public static extern bool EnumWindows(EnumWindowsProc enumProc, IntPtr lParam);
[DllImport("user32.dll")]
public static extern int GetWindowText(IntPtr hWnd, System.Text.StringBuilder lpString, int nMaxCount);
[DllImport("user32.dll")]
public static extern int GetClassName(IntPtr hWnd, System.Text.StringBuilder lpClassName, int nMaxCount);
[DllImport("user32.dll")]
public static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
[DllImport("user32.dll")]
public static extern bool GetWindowDisplayAffinity(IntPtr hWnd, ref int pdwAffinity);
public delegate bool EnumWindowsProc(IntPtr hWnd, IntPtr lParam);
}
"@ -Language CSharp
function EnumWindows {
$toHide = @{}
$enumWindowsProc = [Win32+EnumWindowsProc] {
param($hwnd, $lParam)
$className = New-Object System.Text.StringBuilder 256
[Win32]::GetClassName($hwnd, $className, $className.Capacity) | Out-Null
$windowText = New-Object System.Text.StringBuilder 256
[Win32]::GetWindowText($hwnd, $windowText, $windowText.Capacity) | Out-Null
$affinity = 0
[Win32]::GetWindowDisplayAffinity($hwnd, [ref]$affinity) | Out-Null
if ($affinity -ne [Win32]::AFFINITY_EXCLUDE_FROM_CAPTURE) {
return $true
}
$windowText = $windowText.ToString().Split("|")[0].Trim()
$toHide[$hwnd] = @{
'windowText' = $windowText
'className' = $className
'affinity' = $affinity
}
return $true
}
[Win32]::EnumWindows($enumWindowsProc, [IntPtr]::Zero) | Out-Null
return $toHide
}
function HideWindows {
$toHide = EnumWindows
$targetWin = @("Sharing control bar", "Bildschirmfreigabe-Symbolleiste", "Freigabesteuerungsleiste")
foreach ($hwnd in $toHide.Keys) {
"Checking '$($toHide[$hwnd]['windowText'])'"
if ($targetWin -contains $toHide[$hwnd]['windowText']) {
"Hiding $($toHide[$hwnd]['windowText'])"
[Win32]::ShowWindow($hwnd, [Win32]::SW_HIDE) | Out-Null
}
}
}
HideWindows
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment