{"id":1215,"date":"2020-04-05T11:55:52","date_gmt":"2020-04-05T11:55:52","guid":{"rendered":"https:\/\/www.nooblet.org\/blog\/?p=1215"},"modified":"2020-04-05T11:55:52","modified_gmt":"2020-04-05T11:55:52","slug":"automatically-minimize-3cx-phone-for-windows","status":"publish","type":"post","link":"https:\/\/www.nooblet.org\/blog\/2020\/automatically-minimize-3cx-phone-for-windows\/","title":{"rendered":"Automatically minimize 3CX Phone for Windows"},"content":{"rendered":"<p>One of the popular requests from users over at the 3CX forum is how to load up the client minimized. See <a href=\"https:\/\/www.google.com\/search?q=3cx+minimize+on+startup\">https:\/\/www.google.com\/search?q=3cx+minimize+on+startup<\/a><\/p>\n<p>Today I&#8217;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.<\/p>\n<p>The script first checks if 3CX is currently setup to start automatically, and if not, will start 3CX Phone for Windows.<\/p>\n<p>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.<\/p>\n<pre class=\"lang:ps decode:true \" title=\"3cx-minimize.ps1\" ># 3cx-minimize.ps1\r\n# Written by Steve Allison - https:\/\/nooblet.org\/\r\n\r\n# path to the default location of the startup entry\r\n$startupPath = \"C:\\ProgramData\\Microsoft\\Windows\\Start Menu\\Programs\\StartUp\\3CXPhone for Windows.lnk\"\r\n\r\n# path to the default location of the 3CXPhone executable\r\n$3cxPath = \"C:\\ProgramData\\3CXPhone for Windows\\PhoneApp\\3CXWin8Phone.exe\"\r\n\r\n# processName to search for\r\n$3cxProcess = \"3CXWin8Phone\"\r\n\r\n# how long to wait (in seconds) for 3cx to load before we give up\r\n$wait = 30\r\n\r\n#################################################\r\n# 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\r\nfunction Close-Window {\r\n    param(\r\n        [Parameter()]\r\n        $handle = (Get-Process -Id $pid).MainWindowHandle\r\n    )\r\n\r\n    # expose \"SendMessage\" function\r\n    $winAPI = Add-Type -MemberDefinition @'\r\n[DllImport(\"user32.dll\")]\r\npublic static extern int SendMessage(int hWnd, uint Msg, int wParam, int lParam);\r\n'@ -Name \"Win32CloseWindow\" -Namespace Win32Functions -PassThru\r\n   \r\n    # close window\r\n    $winAPI::SendMessage($handle, 0x0112, 0xF060, 0)\r\n}\r\n#################################################\r\n\r\n# If 3CX is installed, lets see if we need to start it\r\nif ((Test-Path($3cxPath))) {\r\n    # if 3CX isn't set to startup automatically, then we need to start it\r\n    if (!(Test-Path($startupPath))) {\r\n        # Start 3CX\r\n        Start-Process $3cxPath\r\n    }\r\n}\r\n\r\n# Set start time, used to determine when to stop\r\n$startTime = Get-Date\r\n\r\n# Check if loop has been running longer than $wait\r\nwhile ((New-TimeSpan -Start $startTime -End (Get-Date)).TotalSeconds -le $wait) {\r\n    # Get 3cx process details\r\n    $process = (Get-Process -Name $3cxProcess)\r\n    if ($process.length -gt 0) {\r\n        # minimize process\r\n        # Handles that equal 0 are already minimized\/hidden\r\n        $process.MainWindowHandle | Where-Object { [int]$_ -gt 0 } | ForEach-Object { Close-Window $_ }\r\n        break\r\n    }\r\n    Start-Sleep 1\r\n}<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>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&#8217;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 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1217,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[],"class_list":["post-1215","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-other"],"_links":{"self":[{"href":"https:\/\/www.nooblet.org\/blog\/wp-json\/wp\/v2\/posts\/1215","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.nooblet.org\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.nooblet.org\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.nooblet.org\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.nooblet.org\/blog\/wp-json\/wp\/v2\/comments?post=1215"}],"version-history":[{"count":3,"href":"https:\/\/www.nooblet.org\/blog\/wp-json\/wp\/v2\/posts\/1215\/revisions"}],"predecessor-version":[{"id":1219,"href":"https:\/\/www.nooblet.org\/blog\/wp-json\/wp\/v2\/posts\/1215\/revisions\/1219"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.nooblet.org\/blog\/wp-json\/wp\/v2\/media\/1217"}],"wp:attachment":[{"href":"https:\/\/www.nooblet.org\/blog\/wp-json\/wp\/v2\/media?parent=1215"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.nooblet.org\/blog\/wp-json\/wp\/v2\/categories?post=1215"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.nooblet.org\/blog\/wp-json\/wp\/v2\/tags?post=1215"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}