I have adjusted the previous 3CX script from 2020 to simply minimize a list of applications. The script will search for matching processes for up to 30 seconds and minimize them. I have this script run on logon. It currently minimizes both 3CX and Voicemeeter Macro Button app.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
$processes = @( @{ Name = '3CXDesktopApp' Result = $false }, @{ Name = 'VoicemeeterMacroButtons' Result = $false } ) # how long to wait (in seconds) for processes to load before we give up $wait = 30 ################################################# # idea from https://community.idera.com/database-tools/powershell/ask_the_experts/f/powershell_for_windows-12/11584/how-to-script-clicking-on-x-to-close-window function Close-Window { param( [Parameter()] $handle = (Get-Process -Id $pid).MainWindowHandle ) # expose "SendMessage" function $winAPI = Add-Type -MemberDefinition @' [DllImport("user32.dll")] public static extern int SendMessage(int hWnd, uint Msg, int wParam, int lParam); '@ -Name "Win32CloseWindow" -Namespace Win32Functions -PassThru # close window $winAPI::SendMessage($handle, 0x0112, 0xF060, 0) } ################################################# # Set start time, used to determine when to stop $startTime = Get-Date # Check if loop has been running longer than $wait while (((New-TimeSpan -Start $startTime -End (Get-Date)).TotalSeconds) -le $wait) { # if this is still true at end of loop, we break $found = $true Foreach ($item in $processes.Keys) { if ($true -ne $item.Result) { $process = (Get-Process -Name $item.Name) if ($process.length -gt 0) { # minimize process # Handles that equal 0 are already minimized/hidden $process.MainWindowHandle | Where-Object { [int]$_ -gt 0 } | ForEach-Object { Close-Window $_ } # mark we have completed this one $processes[$item].Result = $true } else { $found = $false } Start-Sleep 1 } } # still true after loop, so we found all the processes if ($found) { break } } |