PowerShell script and Window Focus
I have a script that worked under Windows 10 1903. It does not work under Windows 10 1909. I'm hoping someone here can shed some light on what is happening and maybe suggest a workaround. I'm using Zoom for online classes and found that if I get busy working in another window and get asked a question, it normally takes a few seconds to find the proper Zoom window so I can unmute my microphone and answer. I came up with a solution to use an application called Touch Portal which allows me to run a script that brings the proper Zoom window into focus by simply pressing a button in the Touch Portal interface. This worked well in Windows 10 1903. However, in 1909 the Zoom icon in the taskbar simply starts flashing and does not bring the window into focus. I have confirmed that the script does work in a PowerShell console in 1909; it just doesn't fully work when pressing the Touch Portal button. I have included the script below. I'm assuming the change occurred to prevent rogue applications from stealing window focus. Just hoping there is some kind of work around to allow it to work again. (The bulk of the script came from here.)
#requires -Version 2
function Show-Process($Process, [Switch]$Maximize)
{
$sig = '
[DllImport("user32.dll")] public static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow);
[DllImport("user32.dll")] public static extern int SetForegroundWindow(IntPtr hwnd);
'
if ($Maximize) { $Mode = 3 } else { $Mode = 4 }
$type = Add-Type -MemberDefinition $sig -Name WindowAPI -PassThru
$hwnd = $process.MainWindowHandle
$null = $type::ShowWindowAsync($hwnd, $Mode)
$null = $type::SetForegroundWindow($hwnd)
}
$ZoomTime = Get-Process Zoom | select id, starttime
If ($ZoomTime[0].starttime -gt $ZoomTime[1].starttime) {
$ZoomPID = $ZoomTime[0].id
} else {
$ZoomPID = $ZoomTime[1].id
}
Show-Process -Process (Get-Process -ID $ZoomPID)