One of the popular requests from users over at the 3CX forum is how to load up the client minimized. See https://www.google.com/search?q=3cx+minimize+on+startup
Today I’ve written some powershell that when also run at startup will close the 3CX Phone for Windows application automatically. I run this as a scheduled task triggered on login.
The script first checks if 3CX is currently setup to start automatically, and if not, will start 3CX Phone for Windows.
The script then checks once a second for the app to load and will close to tray. The script will wait $wait seconds before closing if the app is not loaded.
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 |
# 3cx-minimize.ps1 # Written by Steve Allison - https://nooblet.org/ # path to the default location of the startup entry $startupPath = "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp\3CXPhone for Windows.lnk" # path to the default location of the 3CXPhone executable $3cxPath = "C:\ProgramData\3CXPhone for Windows\PhoneApp\3CXWin8Phone.exe" # processName to search for $3cxProcess = "3CXWin8Phone" # how long to wait (in seconds) for 3cx 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) } ################################################# # If 3CX is installed, lets see if we need to start it if ((Test-Path($3cxPath))) { # if 3CX isn't set to startup automatically, then we need to start it if (!(Test-Path($startupPath))) { # Start 3CX Start-Process $3cxPath } } # 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) { # Get 3cx process details $process = (Get-Process -Name $3cxProcess) 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 $_ } break } Start-Sleep 1 } |