Clear all and only persistent (static) routes on Windows

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 /f
but this wouldn't remove them from the currently active routes.

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
)