rem This script is fired from Task Scheduler will check connectivity to VPN server.
ping 192.168.1.1 -n 10 | findstr /r /c:”Reply from \d.\d.\d.\d.* bytes=\d.time[<=]\d. TTL=\d*” && goto :finished
:run
rem be sure to kill previous (closed) openvpn process so reconnecting actually works!
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”
timeout 1
“C:\Program Files\OpenVPN\bin\openvpn-gui.exe” –command connect “C:\Program Files\OpenVPN\config\SGPFW1-UDP4-1194-config.ovpn”
timeout 5
“C:\Program Files\OpenVPN\bin\openvpn-gui.exe” –connect SGPFW1-UDP4-1194-config
:finished
Copy above code and make .cmd
ex: VPN-Connection.cmd
Changes in code as per you configuration
- 192.168.1.1 —> add your VPN server IP
- C:\Program Files\OpenVPN —> add your VPN path
Configure in Task Scheduler
Press Windows Key Search Task Scheduler
Click on Action –> Create Task