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

Hi,
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.

Code:
@ECHO OFF
SETLOCAL
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%

GOTO :EOF
Reply With Quote