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