Reconnect via script?

How to customize and extend your OpenVPN installation.
Post Reply
Hossy
OpenVpn Newbie
Posts: 2
Joined: Mon Sep 26, 2016 1:07 pm

Reconnect via script?

Post by Hossy » Mon Sep 26, 2016 1:16 pm

Periodically, my VPN tunnel will partially drop (the icon in the tray turns yellow, VPN IP still present/pingable, no traffic can pass over VPN) and OpenVPN is unable to automatically reconnect. Not sure why this is happening, but I know that if I manually disconnect and reconnect, everything is working again.

Instead of doing this manually, I'm writing a script to do this. I'm running Windows 7, so I decided to write PowerShell. I'm looking for a way to reconnect via script when the VPN tunnel partially drops and so far the only thing I've found is to just kill the openvpn.exe process.

In my testing, the problem with killing the openvpn.exe process is that it leaves Windows in a funky networking state and I can't ping out my network interface. I did find that if I disable then enable the network interface (not the TAP), then I can ping again and then reconnect. However, disconnecting the machine from the network, albeit temporarily, causes issues with other programs running on the machine, so I need to find another way.

Has anyone run into this issue before or can you think of anything else to try?

Hossy
OpenVpn Newbie
Posts: 2
Joined: Mon Sep 26, 2016 1:07 pm

Re: Reconnect via script?

Post by Hossy » Mon Sep 26, 2016 1:39 pm

I just discovered that when I kill the openvpn.exe process, the reason I'm unable to ping out my network interface is because the routing table doesn't have a default route. Apparently upon connection, openvpn.exe changes the Windows routing table, but when I kill it (even not using the -Force option), the routes are not changed back leaving Windows with nowhere to go. Disabling/Enabling the network interface will reset the routes, but I need to find a different way of resetting the routes without disabling the network interface.

Post Reply