yukaputz Posted September 14, 2018 Share Posted September 14, 2018 Hi, I'm trying to make a small vpn watcher program. Openvpn client doesn't always reconnect when the vpn drops and my users are utter idiots. Apparently "check your vpn" regularly is beyond their comprehension. What I would like to do is to make a program that runs as a service in windows regarless of desktop login state, that executes a run command if the internal ip of the vpn server cannot be reached. I'd like like the entire process to be hidden from the user (Hence why task scheduler won't work because of run as user and run whether logged in or not hassle) I am new to autoit and programming in general. Openvpn has a nifty command line option. If you hit run and put this in and the vpn gui is loaded in the taskbar, the vpn will connect. "C:\Program Files (x86)\OpenVPN Technologies\OpenVPN Client\core\ovpncli.exe" -q connect So I read some and watched some and came up with this to see if autoit could call the ovpncli.exe first. Global $pingvpn $pingvpn = Ping("10.1.0.6",250) If $pingvpn = 0 Then Run ("C:\Program Files (x86)\OpenVPN Technologies\OpenVPN Client\core\ovpncli.exe" ["C:\Program Files (x86)\OpenVPN Technologies\OpenVPN Client\core\" ["-q connect"]]) Else EndIf And no joy. "C:\Users\mike\vpn.au3" (6) : ==> Subscript used on non-accessible variable.: Run ("C:\Program Files (x86)\OpenVPN Technologies\OpenVPN Client\core\ovpncli.exe" ["C:\Program Files (x86)\OpenVPN Technologies\OpenVPN Client\core\" ["-q connect"]]) Run ("C:\Program Files (x86)\OpenVPN Technologies\OpenVPN Client\core\ovpncli.exe" ^ ERROR ->11:43:50 AutoIt3.exe ended.rc:1 +>11:43:50 AutoIt3Wrapper Finished. >Exit code: 1 Time: 1.118 I think I am following the format for Run correctly? Also, could anyone point me towards how to add a 10 minute wait and restart for the Else statement? Link to comment Share on other sites More sharing options...
BigDaddyO Posted September 14, 2018 Share Posted September 14, 2018 something like this should work, but when executing files, I like to get the path from the registry using RegRead instead of hard-coding. While 1 Ping("10.1.0.6",250) If @error Then ShellExecute("C:\Program Files (x86)\OpenVPN Technologies\OpenVPN Client\core\ovpncli.exe", "-q connect") Sleep(600000) ;sleep 10min WEnd yukaputz 1 Link to comment Share on other sites More sharing options...
jdelaney Posted September 14, 2018 Share Posted September 14, 2018 Or wrap the entire run with a single quote like '"your exe.exe" param1 param2' IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window. Link to comment Share on other sites More sharing options...
yukaputz Posted September 14, 2018 Author Share Posted September 14, 2018 Big D, that worked great, only issue is a command line window pops for just a second, I looked at the ShellExecute command and saw the flag [@SW_HIDE = Hidden window] I stabbed that into the end of the command but syntax error. When adding the option flag [x @SW_HIDE = Hidden ShellExecute("C:\Program Files (x86)\OpenVPN Technologies\OpenVPN Client\core\ovpncli.exe", "-q connect" [, @SW_HIDE = Hidden window]) Here is the error If @error Then ShellExecute("C:\Program Files (x86)\OpenVPN Technologies\OpenVPN Client\core\ovpncli.exe", "-q connect" [, @SW_HIDE = Hidden window ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^ Am I reading the syntax wrong? How do I set the hide window flag? ShellExecute ( "filename" [, "parameters" [, "workingdir" [, "verb" [, showflag]]]] ) Link to comment Share on other sites More sharing options...
BigDaddyO Posted September 14, 2018 Share Posted September 14, 2018 (edited) ShellExecute("C:\Program Files (x86)\OpenVPN Technologies\OpenVPN Client\core\ovpncli.exe", "-q connect", "", "open", @SW_HIDE) Edited September 14, 2018 by BigDaddyO Link to comment Share on other sites More sharing options...
yukaputz Posted September 14, 2018 Author Share Posted September 14, 2018 It only pops the cmd for a brief moment if the vpn is actually down which, is live-able. Because the VPN is gonna stay up for the most part....I hope. 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