Is there a simple way of doing this via a shell command / batch ? A VBScript would also be ok.
4 Answers
To clear all routes, use:
route -f
To clear only persistent routes, you could use
reg delete HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\PersistentRoutes /va /fbut this wouldn't remove them from the currently active routes.

- 10,162
- 1
- 26
- 42
-
I have loads of persistent routes, but I don't see any on that regkey. Are they stored somewhere else these days (Windows 10)? – NickG Mar 28 '18 at 15:00
-
@NickG: Not sure. Are you talking about IPv4 or IPv6 routes? – user1686 Mar 28 '18 at 15:07
-
@user1686 `route -f` is not to be run remotely. And the PC/server needs to be rebooted after that. – SebMa Dec 07 '20 at 16:16
-
@SebMa: It clears all routes, what did you expect to happen? – user1686 Dec 07 '20 at 16:19
To delete all IPv4 persistent routes except the default route :
for /f "skip=3 tokens=4,6" %e in ('netsh int ipv4 sh route store^=persistent ^| findstr -v 0.0.0.0/0') do route delete -4 -p %e %f
To delete all IPv6 persistent routes except the default route :
for /f "skip=3 tokens=4,6" %e in ('netsh int ipv6 sh route store^=persistent ^| findstr -v ::/0') do route delete -6 -p %e %f

- 359
- 1
- 10
Here is a cmd-script that extracts the static routes from the registry, and issues route delete
commands for each of them.
This method removes them both from the stored list of persistent routes, and from the currently active routes.
It also deletes the default route if it's found in the registry :
@echo off
set key=HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\PersistentRoutes
for /f "tokens=1,2,3,* delims=," %%i in ('reg query %key% ^| find "REG_SZ"') do (
route delete %%i mask %%j %%k
)
To prevent removing the default route, you can type this :
@echo off
set key=HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\PersistentRoutes
for /f "tokens=1,2,3,* delims=," %%i in ('reg query %key% ^| find /v "0.0.0.0,0.0.0.0" ^| find "REG_SZ"') do (
route delete %%i mask %%j %%k
)

- 359
- 1
- 10

- 331
- 1
- 7
This can be done as a basic for-loop allowing you to clear the routes correctly for the existing and future routes.
( And without getting involved in reviewing or editing any registry items) using a simple route print piped into a find and looped into a route delete.
FOR /F "TOKENS=1-5" %a IN ('ROUTE PRINT ^| FIND /I /V "On-Link" ^| FINDSTR /E /R /C:" *\.[0-9]*[0-9] *[0-9][0-9]*"') DO @(IF /I "%~e" EQU "" ( ROUTE DELETE %a MASK %b %c ) )

- 119
- 6