@echo off
TITLE Revert Metered Connections
COLOR 1F
echo.

cd %systemroot%\system32
call :IsAdmin
CLS
TITLE Windows 10 Revert Metered Connections
cls
color 1f
echo.
ver | findstr /i " 10\.0\." > nul
IF "%ERRORLEVEL%" EQU "0" goto :Win10
echo This script only for use on Windows 10 Kernels.
echo.
pause
exit

:Win10
echo.
echo Simple script to revert all network connections to NOT metered. 
echo.

REM Setting the value after the = sign to 1 sets as NOT metered {default setting}, 2 sets as metered.

SET NM_3G=1
SET NM_4G=1
SET NM_Default=1
SET NM_LAN=1
SET NM_WiFi=1

IF DEFINED NM_3G 	REG add "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkList\DefaultMediaCost" /v "3G" /t REG_DWORD /d "%NM_3G%" /f >NUL 2>&1
IF DEFINED NM_4G 	REG add "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkList\DefaultMediaCost" /v "4G" /t REG_DWORD /d "%NM_4G%" /f >NUL 2>&1
IF DEFINED NM_Default 	REG add "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkList\DefaultMediaCost" /v "Default" /t REG_DWORD /d "%NM_Default%" /f >NUL 2>&1
IF DEFINED NM_LAN 	REG add "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkList\DefaultMediaCost" /v "Ethernet" /t REG_DWORD /d "%NM_LAN%" /f >NUL 2>&1
IF DEFINED NM_WiFi 	REG add "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkList\DefaultMediaCost" /v "WiFi" /t REG_DWORD /d "%NM_WiFi%" /f >NUL 2>&1

SET "DSRestart=No"
SET "UCM=On"

reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\DeviceSetup" /v "CostedNetworkPolicy" /t REG_DWORD /d "1" /f >nul 2>&1

for /f %%W in ('REG query "HKLM\SOFTWARE\Microsoft\DusmSvc\Profiles"') do (
	reg delete "%%W\*" /v "BackgroundRestriction" /f >nul 2>&1
	reg delete "%%W\*" /v "UserCost" /f >nul 2>&1 && ( SET "UCM=Off" & SET "DSRestart=Yes" )
	reg delete "%%W\*" /v "UserDataPlan" /f >nul 2>&1
)

for /f %%W in ('REG query "HKLM\SOFTWARE\Microsoft\DusmSvc\Profiles"') do (
	FOR /F %%X in ('REG query "%%W"') DO (
		REG delete "%%X" /v "BackgroundRestriction" /f >NUL 2>&1
		REG delete "%%X" /v "UserCost" /f >NUL 2>&1 && ( SET "UCM=Off" & SET "DSRestart=Yes" )
		REG delete "%%X" /v "UserDataPlan" /f >nul 2>&1
	)
)

if /I "%UCM%"=="Off" echo UserCost {Non-Metered} set to 0 {Off}.
IF /I "%DSRestart%"=="Yes" cmd /c "net stop "DusmSvc"" >NUL 2>&1 && ( sc start "DusmSvc" >NUL 2>&1 && echo DusmSvc Service Restarted. ) || TIMEOUT /T 1 >nul & sc start "DusmSvc" >NUL 2>&1 && echo DusmSvc Service Restarted.

echo.
echo Done. Note: Reboot is required to reset this setting.

:Finished
TIMEOUT /T 5 >NUL 2>&1
exit

:IsAdmin
Reg.exe query "HKU\S-1-5-19\Environment"
If Not %ERRORLEVEL% EQU 0 (
 Cls
 echo.
 Echo You must have administrator rights to continue...
 echo.
 Pause
 Exit
)
