From Newsgroup: alt.msdos.batch
On Wed, 23 Jul 2025 21:10:19 -0000 (UTC), Marion wrote :
Basically you need to give Microsoft Windows a few seconds to set the route where the default of 0 can be too quick for Windows to respond fast enough.
Here's another very useful batch file, not just for the thousands of free
VPN server configs out there but for anyone who needs to *remove* lines.
This comments out specific lines from thousands of existing files (where it doesn't matter if the line itself has comments at the end of that line).
BEFORE:
auth-retry interact ; allows retries without restarting
pull-filter ignore "ping" ; try to ignore server ping of 3
pull-filter ignore "ping-restart" ; try to ignore server ping of 10
AFTER
;auth-retry interact ; allows retries without restarting
;pull-filter ignore "ping" ; try to ignore server ping of 3
;pull-filter ignore "ping-restart" ; try to ignore server ping of 10
ALL OTHER LINES LEFT ALONE (works on all *.ovpn files in cwd & deeper)
@echo off
REM commentovpn.bat (comments out specific lines found in cwd files & below)
setlocal enabledelayedexpansion
REM ##########################################################################
REM ### WARNING: BACK UP YOUR OVPN FILES BEFORE RUNNING THIS SCRIPT! ###
REM ### This script modifies .ovpn files to improve OpenVPN connection ###
REM ### reliability by commenting out specific directives that might ###
REM ### conflict with server settings. ###
REM ##########################################################################
REM Set the TARGET_DIR to the directory where your .ovpn files are located.
REM If you leave it as '.', it will process files in the same directory as the script
REM and all its subdirectories.
set "TARGET_DIR=."
echo.
echo Starting to process .ovpn files in "%TARGET_DIR%" and its subdirectories...
echo.
for /r "%TARGET_DIR%" %%F in (*.ovpn) do (
echo Processing "%%F"...
set "TEMP_FILE=%%F.tmp"
set "MODIFIED_FLAG=0" ; Flag to track if any changes were made to the current file
REM Create a temporary file with the modified content
(
for /f "usebackq delims=" %%i in ("%%F") do (
set "original_line=%%i"
set "processed_line=!original_line!" ; Start with the original line for this iteration
set "line_already_modified=0" ; Flag for current line to prevent multiple comments on one line
REM Check if the line is already commented out. If so, don't modify it.
if "!original_line:~0,1!"==";" (
REM Do nothing, line is already commented.
) else if "!original_line:~0,1!"=="#" (
REM Do nothing, line is already commented.
) else (
REM The line is not commented, so check if it contains any of our target directives.
REM Check for 'pull-filter ignore "ping"'
echo "!original_line!" | findstr /I /L /C:"pull-filter ignore \"ping\"" >nul
if not errorlevel 1 (
set "processed_line=;!original_line!"
set "MODIFIED_FLAG=1"
set "line_already_modified=1"
)
REM Check for 'pull-filter ignore "ping-restart"'
if "!line_already_modified!"=="0" (
echo "!original_line!" | findstr /I /L /C:"pull-filter ignore \"ping-restart\"" >nul
if not errorlevel 1 (
set "processed_line=;!original_line!"
set "MODIFIED_FLAG=1"
set "line_already_modified=1"
)
)
REM Check for 'auth-retry interact'
if "!line_already_modified!"=="0" (
echo "!original_line!" | findstr /I /L /C:"auth-retry interact" >nul
if not errorlevel 1 (
set "processed_line=;!original_line!"
set "MODIFIED_FLAG=1"
set "line_already_modified=1"
)
)
)
REM Always echo the (potentially modified) line to the temporary file
echo !processed_line!
)
) > "!TEMP_FILE!"
REM Replace the original file with the modified temporary file, but only if changes were made
if "!MODIFIED_FLAG!"=="1" (
move /y "!TEMP_FILE!" "%%F" >nul
echo Modified "%%F".
) else (
del "!TEMP_FILE!" >nul
echo No changes needed for "%%F".
)
echo.
)
echo All .ovpn files processed.
echo.
echo Remember to restart your OpenVPN client(s) for changes to take effect.
pause
--
Obviously this works for all text files of any extension & content,
which is why it's a generally useful script for commenting out
spedific lines in any number of files in any Windows hierarchy.
--- Synchronet 3.21a-Linux NewsLink 1.2