Hi again, I found another way to deal with my problem, as it may help other users I decided to post it here.
The first script is ran when the VPN goes UP or DOWN :
VPN_up_down.bat
@echo off
set vpn=%config%
set vpn=%vpn:.ovpn=%
cd "C:\Program Files (x86)\OpenVPN\config\logs"
echo %date% %time:~0,8% - %vpn% %script_type% >> reco_log.txt
REM we try to reconnect only if the disconnection is not coming from the user to prevent unstoppable program
if "%signal%" == "sigterm" exit
setlocal ENABLEDELAYEDEXPANSION
if "%script_type%" == "down" (
REM if vpn is down, we try with another server
set /p vpnserver=<vpnserverlist.txt
more +1<vpnserverlist.txt>temp
echo !vpnserver!>>temp
move temp vpnserverlist.txt
taskkill /F /IM openvpn-gui.exe
taskkill /F /IM openvpn.exe
del "C:\Program Files (x86)\OpenVPN\log\*.log"
start "" "C:\Program Files (x86)\OpenVPN\bin\openvpn-gui.exe" --connect !vpnserver! --silent_connection 1 --show_balloon 0
echo %date% %time:~0,8% - reco !vpnserver! >> reco_log.txt
REM and we check if it is connected
cd "C:\Program Files (x86)\OpenVPN\config\scripts\"
set vpn_UP=!vpnserver!
set vpn_DOWN=%vpn%
start /B "" "VPNCheckUP.bat"
)
and this second script looks into the log file to see if the connection is ok, if it's not it tries to connect to another server :
VPNCheckUP.bat
@echo off
set vpn=%vpn_UP%
set vpn=%vpn:.ovpn =%
ping -n 60 127.0.0.1>NUL
cd "C:\Program Files (x86)\OpenVPN\log"
copy %vpn%.log tmp.log
findstr "Initialization Sequence Completed" tmp.log
if %errorlevel%==0 (
REM if the VPN connected we log it
cd "C:\Program Files (x86)\OpenVPN\config\logs"
echo %date% %time:~0,8% - %vpn% Running >> reco_log.txt
exit
) else (
REM else (VPN not connected) we run it with another server
cd "C:\Program Files (x86)\OpenVPN\config\logs"
echo %date% %time:~0,8% - %vpn% Not Running >> reco_log.txt
setlocal ENABLEDELAYEDEXPANSION
set /p vpnserver=<vpnserverlist.txt
more +1<vpnserverlist.txt>temp
echo !vpnserver!>>temp
move temp vpnserverlist.txt
taskkill /F /IM openvpn-gui.exe
taskkill /F /IM openvpn.exe
del "C:\Program Files (x86)\OpenVPN\log\*.log"
start "" "C:\Program Files (x86)\OpenVPN\bin\openvpn-gui.exe" --connect !vpnserver! --silent_connection 1 --show_balloon 0
echo %date% %time:~0,8% - reco !vpnserver! >> reco_log.txt
REM And we check if it is connected
cd "C:\Program Files (x86)\OpenVPN\config\scripts\"
set vpn_UP=!vpnserver!
set vpn_DOWN=%vpn%
start /B "" "VPNCheckUP.bat"
)
The file vpnserverlist.txt contains a list of ovpn files:
server1.ovpn
server2.ovpn
...
Hope this will help others!
Note : I'm no script dev so feel free to (upgrade/correct/adapt to your need) my proposition