dejhost Posted March 15, 2020 Share Posted March 15, 2020 Dear Ladies and Gentlemen, The following part of a script toggles a wireguard tunnel. It works fine as long as I run the script hitting "F5" in Scite ("go"). The wireguard-client runs in my system tray. Once the script is built and the resulting "exe" is executed, I receive an Error message: the ControlClick command returns 0. All commands prior this have been tested using messageboxes - they work fine. #include <Chrome.au3> #include <GUIConstantsEx.au3> Opt("WinTitleMatchMode", 2) Opt("MouseCoordMode", 2) Opt("MouseClickDelay", 20) ;10 milliseconds Opt("SendKeyDelay", 20) ;5 milliseconds HotKeySet("{F6}", "WG_Toggle") ;===TOGGLE WIREGUARD=== Func WG_Toggle() ;This Function toggles Wireguard tunnel Local $hWnd = WinWait ("WireGuard") If $hWnd = 0 Then msgbox(1,"Error WinWait", $hWnd) If ControlGetText($hWnd, "", "[CLASS:Button; INSTANCE:3]") = "&Activate" Then If ControlClick($hWnd, "&Activate", "[CLASS:Button; INSTANCE:3]") = 0 Then MsgBox(1, "Error while activating WG", "An error occured while activating Wireguard.") ElseIf ControlGetText($hWnd, "", "[CLASS:Button; INSTANCE:3]") = "&Deactivate" Then If ControlClick($hWnd, "&Deactivate", "[CLASS:Button; INSTANCE:3]") = 0 Then MsgBox(1, "Error while deactivating WG", "An error occured while deactivating Wireguard.") Else MsgBox(1, "Error", "WG function not responding") EndIf EndFunc ;==>WG_Toggle Any comment that might help me to further troubleshoot the issue or how to achieve the toggle in an easier/more reliable way is much appreciated. Thank you in advance! Link to comment Share on other sites More sharing options...
Danp2 Posted March 15, 2020 Share Posted March 15, 2020 You shouldn't need to pass a value for the 2nd parameter of ControlClick since you are passing a hWnd for the 1st parameter. Try changing the 2nd parameter of ControlClick to "". Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
Nine Posted March 16, 2020 Share Posted March 16, 2020 As described in help file : When you use a window handle for the title parameter then the text parameter is completely ignored. So changing it in any way, won't give a different result... “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) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
dejhost Posted March 16, 2020 Author Share Posted March 16, 2020 There has been an update for WG-client. Now, I do not seem to achieve any effect with my controlclick command. ;===TOOGLE WIREGUARD=== Func WG_Toggle() ;This Function toggles Wireguard tunnel msgbox(1,"hello", "world",1) If WinExists("WireGuard") Then Local $hWnd = WinWait("WireGuard") If $hWnd = 0 Then msgbox(1,"Error WinWait", $hWnd) Msgbox(1,"Current status of WG", ControlGetText($hWnd, "", "[CLASS:Button; INSTANCE:3]"),1) If ControlGetText($hWnd, "", "[CLASS:Button; INSTANCE:3]") = "&Activate" Then ;ControlClick("WireGuard", "&Activate", "[CLASS:Button; INSTANCE:3]") WinActivate($hWnd) WinSetState ( $hWnd, "", @SW_MAXIMIZE ) If ControlClick($hWnd, "", "[CLASS:Button; INSTANCE:3]") <> 7 Then MsgBox(1, "ControlClick executed", ControlClick($hWnd, "", "[CLASS:Button; INSTANCE:3]")) ElseIf ControlGetText($hWnd, "", "[CLASS:Button; INSTANCE:3]") = "&Deactivate" Then If ControlClick($hWnd, "", "[CLASS:Button; INSTANCE:3]") <> 7 Then MsgBox(1, "ControlClick executed", ControlClick($hWnd, "", "[CLASS:Button; INSTANCE:3]")) Else MsgBox(1, "Error", "WG function not responding") EndIf Else Msgbox(1,"Wireguard", "Wireguard is not running.",1) EndIf Exit EndFunc ;==>WG_Toggle Since the WG-tunnel isn't active, it is enough to trouble shoot the attempt to activate it. I get the following messages: "hello world" message, "Current status of WG": &activate "ControlClick executed": 1 But the WG-client does not react in any way. Do you have a recommendation for another command that I could try? I would like to avoid mouseclicks... Thank you. Link to comment Share on other sites More sharing options...
bogQ Posted March 16, 2020 Share Posted March 16, 2020 (edited) Why there is not any while loop to keep script alive or i am missing something? nwm its a part of script Edited March 16, 2020 by bogQ TCP server and client - Learning about TCP servers and clients connectionAu3 oIrrlicht - Irrlicht projectAu3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related) There are those that believe that the perfect heist lies in the preparation.Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost. Link to comment Share on other sites More sharing options...
Nine Posted March 16, 2020 Share Posted March 16, 2020 Have you tried using #RequireAdmin ? dejhost 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) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
Earthshine Posted March 16, 2020 Share Posted March 16, 2020 Use the frozen tool and show me exactly which button do you want to click My resources are limited. You must ask the right questions Link to comment Share on other sites More sharing options...
bogQ Posted March 16, 2020 Share Posted March 16, 2020 (edited) i removed ;~ Opt("WinTitleMatchMode", 2) just to b safe works for me compiled untill click part expandcollapse popup#include <GUIConstantsEx.au3> ;~ Opt("WinTitleMatchMode", 2) Opt("MouseCoordMode", 2) Opt("MouseClickDelay", 20) ;10 milliseconds Opt("SendKeyDelay", 20) ;5 milliseconds HotKeySet("{F6}", "WG_Toggle") While 1 Sleep(10) WEnd ;===TOOGLE WIREGUARD=== Func WG_Toggle() ;This Function toggles Wireguard tunnel If WinExists("WireGuard") Then Local $hWnd = WinGetHandle("WireGuard") If @error Then msgbox(1,"Error WinGetHandle", $hWnd) $check = WinActivate($hWnd) If $check = 0 Then msgbox(1,"Error WinActivate", $hWnd) $check = WinWaitActive($hWnd) If $check = 0 Then msgbox(1,"Error WinWaitActive", $hWnd) Msgbox(1,"Current status of WG", ControlGetText($hWnd, "", "[CLASS:Button; INSTANCE:3]"),1) If ControlGetText($hWnd, "", "[CLASS:Button; INSTANCE:3]") = "&Activate" Then ;ControlClick("WireGuard", "&Activate", "[CLASS:Button; INSTANCE:3]") If ControlClick($hWnd, "", "[CLASS:Button; INSTANCE:3]") <> 7 Then MsgBox(1, "ControlClick executed", ControlClick($hWnd, "", "[CLASS:Button; INSTANCE:3]")) ElseIf ControlGetText($hWnd, "", "[CLASS:Button; INSTANCE:3]") = "&Deactivate" Then If ControlClick($hWnd, "", "[CLASS:Button; INSTANCE:3]") <> 7 Then MsgBox(1, "ControlClick executed", ControlClick($hWnd, "", "[CLASS:Button; INSTANCE:3]")) Else MsgBox(1, "Error", "WG function not responding") EndIf Else Msgbox(1,"WireGuard", "WireGuard is not running.") EndIf EndFunc ;==>WG_Toggle But note that your calling 2 times controlclick one infront msgbox in if condittion and second time inside of msgbox itself! edit: and btw ControlClick can return only 0 or 1 so i do not understand "<> 7" Edited March 16, 2020 by bogQ TCP server and client - Learning about TCP servers and clients connectionAu3 oIrrlicht - Irrlicht projectAu3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related) There are those that believe that the perfect heist lies in the preparation.Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost. Link to comment Share on other sites More sharing options...
Nine Posted March 16, 2020 Share Posted March 16, 2020 (edited) You did not answer our questions Earthshine and me. And yes 7 is not a valid return value... Edited March 16, 2020 by Nine “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) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
dejhost Posted March 16, 2020 Author Share Posted March 16, 2020 Hi guys, thanks for your input. The button I want to click: 7 is not a return value, correct. But I wanted to get the result in any case - for troubleshooting purposes, so I changed from 0 to 7... 🙂 I am in phone conferences right now - will come back to you ASAP. Link to comment Share on other sites More sharing options...
Danp2 Posted March 16, 2020 Share Posted March 16, 2020 1 hour ago, bogQ said: But note that your calling 2 times controlclick one infront msgbox in if condittion and second time inside of msgbox itself! Good point. Wouldn't this activate and then deactivate the VPN on the 2nd click? Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
bogQ Posted March 16, 2020 Share Posted March 16, 2020 (edited) no because you have disable period after clicking on that button for that button Problem is apparently something else: While VPN window is active all autoit hotkeyes are disabled for some strange reason so hotkey will now work (at least for me). As soon as win is not in focus i can use declared hotkeys once more. Control send focus or click already do not work (at least for me) on that button. And no luck with Send() Im confuzed Edited March 16, 2020 by bogQ TCP server and client - Learning about TCP servers and clients connectionAu3 oIrrlicht - Irrlicht projectAu3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related) There are those that believe that the perfect heist lies in the preparation.Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost. Link to comment Share on other sites More sharing options...
dejhost Posted March 16, 2020 Author Share Posted March 16, 2020 The hotkeys do actually work in my case. And yes, of course: I executed the CommandClick twice - by mistake. This is why nothing happened anymore. Removing the second ComandClick in the msg-box, I was back to the original problem: it works as script, but fails as a compiled program. I removed the Opt("WinTitleMatchMode", 2) . No changes - except that other parts of the script don't work anymore. 🙂 So I tried the #RequireAdmin - and now it works! Amazing thing: I spent several hours to save a few seconds now an then. While one should think that I am frustrated: it's always fun to work with autoit, and figure things out with the support of the forum! Thanks so much for your help everyone. Link to comment Share on other sites More sharing options...
Nine Posted March 16, 2020 Share Posted March 16, 2020 You finally tried it “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) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
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