Seminko Posted August 29, 2020 Posted August 29, 2020 (edited) I need to programatically connect to a VPN - I use ProtonVPN. It has some API support but Linux only. (Wasn't able to to make OpenVPN work...) So I decided to give the old AutoIt a shot. I need to right click the icon in tray (hidden) and using the context menu pick 'Connect'. First issue is that the icon doesn't have a ButtonText. Second issue is that even when I try to click an icon which has a button text, the click doesn't click the icon but rather clicks at the spot where the icon would be if the tray container was open. When I run the script and quickly open the tray container (^ icon) the click goes through just fine. No idea on how to get and click the context menu buttons. My code: #include <GuiToolBar.au3> Sleep(1000) ; Find systray handle for "User Promoted Notification Area" Local $hSysTray_Handle = ControlGetHandle('[Class:Shell_TrayWnd]', '', '[Class:ToolbarWindow32;Instance:1]') If @error Then MsgBox(16, "Error", "System tray not found") EndIf ; Find systray handle for "Overflow Notification Area" i.e. hidden icons Local $hSysTray_Handle_Hidden = ControlGetHandle('[Class:NotifyIconOverflowWindow]', '', '[Class:ToolbarWindow32;Instance:1]') If @error Then MsgBox(16, "Error", "Overflow Notification Area not found") EndIf $iSysTray_ButCount = _GUICtrlToolbar_ButtonCount($hSysTray_Handle_Hidden) For $iSysTray_ButtonNumber = 0 To $iSysTray_ButCount - 1 if _GUICtrlToolbar_GetButtonText($hSysTray_Handle_Hidden, $iSysTray_ButtonNumber) = "StrokeIt" Then ConsoleWrite("Found" & @CRLF) _GUICtrlToolbar_ClickButton($hSysTray_Handle_Hidden, $iSysTray_ButtonNumber, "right", False, 1, 0) ExitLoop EndIf Next Edited August 29, 2020 by Seminko typos
Nine Posted August 29, 2020 Posted August 29, 2020 Here how you can do it (used Bluetooth as an example): #NoTrayIcon #include <Constants.au3> #Include <GuiToolBar.au3> _Systray_Hidden () ConsoleWrite ("Error = " & @error & @CRLF) Func _Systray_Hidden () Local $hWnd = WinGetHandle ('[Class:Shell_TrayWnd]') If Not $hWnd Then Return SetError (1) Local $hCtrl = ControlGetHandle($hWnd, "", "Button2") If Not $hCtrl Then Return SetError (2) ControlClick ($hWnd, "", $hCtrl) Sleep (600) $hWnd = WinGetHandle ('[Class:NotifyIconOverflowWindow]') Local $hSysTray = ControlGetHandle($hWnd, '', "ToolbarWindow321") If Not $hSysTray Then Return SetError (3) Local $iSystray_ButCount = _GUICtrlToolbar_ButtonCount($hSysTray) If Not $iSystray_ButCount Then Return SetError (4) For $i = 0 To $iSystray_ButCount-1 ConsoleWrite (_GUICtrlToolbar_GetButtonText($hSysTray, $i) & @CRLF) If StringInStr (_GUICtrlToolbar_GetButtonText($hSysTray, $i), "BlueTooth") Then _GUICtrlToolbar_ClickButton($hSysTray, $i, "left") Sleep (850) ControlSend("[CLASS:#32768]","","","{UP 2}{ENTER}") Return 1 EndIf Next Return SetError (5) EndFunc There shouldn't be more than 1 button without text. If you need more control, use UIAutomation. Seminko 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Multi-Threading Made Easy
Seminko Posted August 29, 2020 Author Posted August 29, 2020 @Nine unfortunately, the context menu appears not to be the native windows context menu with class 32768. Had to use: ControlSend("[REGEXPCLASS:HwndWrapper.*]","","","{TAB}{ENTER}")
Nine Posted August 29, 2020 Posted August 29, 2020 Good workaround. “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Multi-Threading Made Easy
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now