Dec 02 2020 10:05 AM
If I use keyboard media keys to pause music when I receive a call in teams, the notification sound doesn't seem to get dismissed when I answer the call. So, when I later press play, it also resumes playing the teams call sound over my music.
It does seem to go away on it's own eventually, but it's kind of annoying when I want to listen to music!
Nov 16 2022 01:16 PM
Nov 21 2022 03:09 AM
Nov 22 2022 06:46 AM
I had some fun automating the process of changing the Teams executable. First iterations took about 10 to 15 minutes to complete but this one does the job in about 5 seconds. You don't have to use it if you don't trust it but it sets the original EXE aside so if something wrong happens, you can just replace the resulting file from this script with the original
# Getting the filepath for Teams.exe
$FilePath = Join-Path -Path $env:LOCALAPPDATA -ChildPath "Microsoft\Teams\current\Teams.exe"
# Killing all instances of Teams.exe
Get-Process | ? { $_.Path -eq $FilePath} | Stop-Process -Force -Confirm:$False
# Get the Hex and Binary format of the option "HardwareMediaKeyHandling"
$Option = "HardwareMediaKeyHandling"
$HWMKeyHandlingHexArray = ($Option.ToCharArray() | % { [String]::Format("{0:X2}", [System.Convert]::ToUInt32($_)) }) -Join "-"
$HWMKeyHandlingByteArray = [Byte[]]($HWMKeyHandlingHexArray.split("-") | % { "0x{0}" -f $_ })
# Other needed variables
$ValueOffset = 8
$OldValue = 1
$NewValue = 0
# Get Teams as ByteArray and Hex String
$Bytes = [System.IO.File]::ReadAllBytes($FilePath);
$Hex = [System.BitConverter]::ToString($Bytes)
# Get the location of the option in de HexString
$HexIndex = $Hex.IndexOf($HWMKeyHandlingHexArray)
# Calculate the index of the hex to the index of the byte array
# Account for the dashes in the string
$Index = $HexIndex * 2 / 3
# Account for the fact that HEX makes couples of 2 characters for a byte
$Index = $Index / 2
# Build in some safety
$GotIt = $True
For ($i = 0 ; $i -lt $HWMKeyHandlingByteArray.Count ; $i++) {
If ($Bytes[($Index + $i)] -ne $HWMKeyHandlingByteArray[$i]) {
$GotIt = $False
}
}
If ($GotIt -eq $False) {
"Something went wrong calculating the exact location of '{0}'" -f $Option
Break
}
Else {
# Checking for the value of the option
$ValueIndex = $Index + $HWMKeyHandlingByteArray.count + $ValueOffset
If ($Bytes[$ValueIndex] -eq $OldValue) {
# Actually setting the value
"Changing the value of option '{0}' from {1} to {2}" -f $Option, $OldValue, $NewValue
$Bytes[$ValueIndex] = $NewValue
# Set aside the old file for if something went wrong despite the checks in this script
$File = Get-Item -Path $FilePath
$CopyFilePath = Join-Path -Path $File.DirectoryName -ChildPath ("{0}.old{1}" -f $File.BaseName,$File.Extension)
[Void](Copy-Item -Path $FilePath -Destination $CopyFilePath -Force:$False -Confirm:$False)
# Write new teams.exe
[System.IO.File]::WriteAllBytes($FilePath, $Bytes)
}
ElseIf ($Bytes[$ValueIndex] -eq $NewValue) {
"No need to update the value: '{0}' is already set to {1}" -f $Option, $NewValue
}
Else {
"Something isn't correct, the value for option '{0}' is neither {1} or {2} but {3}" -f $Option, $OldValue, $NewValue, $Bytes[$ValueIndex]
}
}
This HEX editing method is the only workable one I've found. It does **bleep** up the Digital Signature so it could get flagged by some EDRs but nothing yet from FortiEDR here.
Nov 22 2022 04:31 PM
Nov 22 2022 10:51 PM
@Hofa Your script gives me this result:
Something isn't correct, the value for option 'HardwareMediaKeyHandling' is neither 1 or 0 but 72
Nov 23 2022 01:46 AM
@OudstandCan you add this in the last Else clause, run the script again and report back with the output?:
[System.BitConverter]::ToString(($Bytes[$ValueIndex..($HWMKeyHandlingByteArray.count + $ValueOffset + 10)]))
Nov 23 2022 01:53 AM
@Hofa the output is longer than the console can display it. I could post the code which is still shown in the console window. Do you want me to do this?
Nov 23 2022 03:59 AM
Oh my bad. Updated:
[System.BitConverter]::ToString(($Bytes[$ValueIndex..($ValueIndex + $HWMKeyHandlingByteArray.count + $ValueOffset + 10)]))
Nov 23 2022 06:06 AM
@Hofa Hey i think Teams got recently updated (I have to redo the hex edit).
This is what i got when run your script
PS C:\Users\User\OneDrive\Workstation> .\Teams_DisableMediaKeysHex.ps1
Something isn't correct, the value for option 'HardwareMediaKeyHandling' is neither 1 or 0 but 72
48-E7-09-47-01-00-00-00-01-00-00-00-00-00-00-00-52-65-73-6F-6C-75-74-69-6F-6E-42-61-73-65-64-44-65-63-6F-64-65-72-50-72-69-6F-72
Nov 23 2022 06:31 AM
Nov 23 2022 06:32 AM
Nov 23 2022 06:33 AM - edited Nov 23 2022 06:36 AM
Works with 16 as the offset for me
Nov 24 2022 05:32 AM
works great on teams 1.5.0.31168 using 16 as the offset, many thanks for providing this script.
Nov 28 2022 04:44 AM
Nov 28 2022 11:26 AM
How was this ever written into the code of MS Teams to begin with?!?!
Dec 01 2022 01:59 AM - edited Dec 01 2022 02:13 AM
Do you happen to have the full script (with updates) to github gists or something similar? 😄 Because if i execute the script, both with offset 12 or 16, teams wont start anymore 😞
Dec 01 2022 02:15 AM
Dec 01 2022 09:39 AM
Dec 01 2022 10:06 AM
@Tpolz Wow interesting. Yep, just tried it and it worked for me. Sort of. At first I tried left ctrl+play and it didn't work (it played the Teams call sound). So I did left ctrl+play again to turn that sound off. Then I tried right ctrl+play and it played my spotify music. Huzzah!
So then I tried left ctrl+play again and this time it played spotify. WTF is going on.
Nice find, btw.