Jump to content

Recommended Posts

Posted

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?

Posted

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]]]] )

 

Posted

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.

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...