View Single Post
Old 12.04.2020, 20:44
sanchezvictor sanchezvictor is offline
I will play nice!
Join Date: Apr 2020
Posts: 3
Default Windows Batch>> Reconnect VPN for windows (OpenVPN)

let me share with you my batch process with windows. The usage is simple:
the process look inside a directory, and randomly select one of the files with "ovpn" extension.

After that, kill the OpenVPN process, and start it again connection with the file choosen.

Hope you find this useful.

EDIT by pspzockerscene:
We recommend using the current/improved versions of that script, see posts of official JD staff below.
Here you can find the version initially posted by user "sanchezvictor":


SET "sourcedir=C:\Users\sanchezvictor\OpenVPN\config"
FOR /f %%a IN (
 'dir /b /a-d "%sourcedir%\*.ovpn"^|find /i /c ".ovpn" '
 ) DO SET /a selection=1 + (%RANDOM% %% %%a)
FOR /f "tokens=1*delims=:" %%a IN (
 'dir /b /a-d "%sourcedir%\*.ovpn"^|findstr /n /i ".ovpn" '
 ) DO IF %%a==%selection% SET filename=%%b
taskkill.exe /F /IM openvpn.exe
taskkill.exe /F /IM openvpn-gui.exe
timeout 1
start /b "" "C:\Program Files\OpenVPN\bin\openvpn-gui.exe" --silent_connection 1 --connect %filename%


Last edited by pspzockerscene; 24.08.2021 at 19:04.
Reply With Quote