I was reading a tutorial on TenForums yesterday on how to reset the Data Usage, but the methods described there only involves the disabling of network adapters and then manually deleting the files contained in the "C:\Windows\System32\sru" folder. As I'm no expert at coding I thought I'd search on the internet on how make a simple batch script to disable the network adapters and then delete the contents of a folder. So I found the required commands on the internet, but my first couple of attempts to reset the Data Usage did not work. Then I searched for a command to take ownership of a folder and I also added a couple of commands to stop and disable the Data Usage service(DusmSvc). The script seemed to work, but only after a restart. I also found that if the Data Usage app page was opened/closed and then running the script some of the files failed to be deleted due to being in use by another process. After some more searching I only discovered the Reset Data Usage V1.0 app of wtarkan here on the MDL forum. I downloaded it and tried it. I immediately noticed that the app did not disable the network adapters(Hint) to reset the Data Usage. While I was checking the sru folder security permissions and only by accident I removed the DPS object. The Data usage page then failed to load the Data Usage statistics. So I searched the internet on how to restore a folders permissions. I found a command to do a backup of a folders permissions, I ran the command on my desktop computer to backup the folder missions of the untouched sru folder then copied it over to my laptop and restored the folder missions of the sru folder. I then searched DPS and typed it in on Blackviper's webpage and found it was the Diagnostic Policy Service(Hint). Here below is the Batch Script I ended up with. As I have mentioned above I'm not an expert coder so any constructive comments about this script would be appreciated. Code: @ECHO OFF :: BatchGotAdmin (Run as Admin code starts) REM --> Check for permissions >nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system" REM --> If error flag set, we do not have admin. if '%errorlevel%' NEQ '0' ( echo Requesting administrative privileges... goto UACPrompt ) else ( goto gotAdmin ) :UACPrompt echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs" echo UAC.ShellExecute "%~s0", "", "", "runas", 1 >> "%temp%\getadmin.vbs" "%temp%\getadmin.vbs" exit /B :gotAdmin if exist "%temp%\getadmin.vbs" ( del "%temp%\getadmin.vbs" ) pushd "%CD%" CD /D "%~dp0" :: BatchGotAdmin (Run as Admin code ends) :: Your codes should start from the following line COLOR 1F ECHO Commencing with Data Usage Reset: ECHO. ECHO Stopping Diagnostic Policy Service ECHO. net stop DPS > NUL 2>&1 ECHO. ECHO Resetting Data Usage echo Y | del /f /q "C:\Windows\System32\sru\*.*" > nul ECHO. ECHO Restarting Diagnostic Policy Service ECHO. net start DPS > NUL 2>&1 ECHO. ECHO Data Usage was Reset to 0 ECHO. ECHO Closing in 5 Seconds.... ping 127.0.0.1 -n 6 >nul 2>&1 exit
I have tweaked the script a little bit. Code: @ECHO OFF :: BatchGotAdmin (Run as Admin code starts) REM --> Check for permissions >nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system" REM --> If error flag set, we do not have admin. if '%errorlevel%' NEQ '0' ( echo Requesting administrative privileges... goto UACPrompt ) else ( goto gotAdmin ) :UACPrompt echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs" echo UAC.ShellExecute "%~s0", "", "", "runas", 1 >> "%temp%\getadmin.vbs" "%temp%\getadmin.vbs" exit /B :gotAdmin if exist "%temp%\getadmin.vbs" ( del "%temp%\getadmin.vbs" ) pushd "%CD%" CD /D "%~dp0" :: BatchGotAdmin (Run as Admin code ends) :: Your codes should start from the following line COLOR 1F CHOICE /C:YN /M "Do you want to reset the Data Usage now?" IF ERRORLEVEL 2 goto no IF ERRORLEVEL 1 goto yes :yes COLOR 2F ECHO. ECHO Commencing with Data Usage Reset: ECHO. ECHO Stopping Diagnostic Policy Service ECHO. net stop DPS > NUL 2>&1 ECHO Resetting Data Usage ECHO Y | del /f /q "C:\Windows\System32\sru\*.*" > nul ECHO. ECHO Restarting Diagnostic Policy Service ECHO. net start DPS > NUL 2>&1 ECHO. CLS ECHO Data Usage was Reset to 0 ECHO. ECHO Closing in 5 Seconds.... ping 127.0.0.1 -n 6 >nul 2>&1 exit :no exit
The "ping 127.0.0.1 -n 6 >nul 2>&1" creates the necessary delay to simulate the "Closing in 5 Seconds....".
do You check the command TIMEOUT parameters, NO... try this: Code: ECHO Closing in 5 Seconds.... timeout /t 5 /NOBREAK >nul 2>&1 I expect from people thinking, not just copy-paste, greetings from the snowy north
Not sure, what exactly triggered it, stopped using it quite a while ago, since it can also act picky if scripting host is disabled/tampered. Aditionally it uses a temp file that i wanted to avoid.
I disabled UAC via the Control panel on my laptop now to test and the script completed without issues.
Then it seems to be the rogue route. The script itself is not affected, it' only the VBS file trying to trigger the UAC promt.
@s1ave77 Please try this script: Code: @ECHO OFF :: BatchGotAdmin REM --> Check for permissions >nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system" REM --> If error flag set, we do not have admin. if '%errorlevel%' NEQ '0' ( echo Requesting administrative privileges... goto UACPrompt ) else ( goto gotAdmin ) :UACPrompt echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs" echo UAC.ShellExecute "cmd.exe", "/C """"%~f0""""", , "runas", 1 >> "%temp%\getadmin.vbs" cscript "%temp%\getadmin.vbs" exit /B :gotAdmin if exist "%temp%\getadmin.vbs" ( del "%temp%\getadmin.vbs" ) pushd "%CD%" CD /D "%~dp0" :: BatchGotAdmin (Run as Admin code ends) :: Your codes should start from the following line COLOR 1F ECHO =============================================== ECHO Windows 10 Data Usage Reset Script ECHO =============================================== ECHO. REM -->Offer the user a choice to run the script or not CHOICE /C:YN /M "Do you want to reset the Data Usage now?" IF ERRORLEVEL 2 goto no IF ERRORLEVEL 1 goto yes :yes COLOR 2F ECHO. ECHO Commencing with Data Usage Reset: ECHO. ECHO Stopping Diagnostic Policy Service ECHO. net stop DPS > NUL 2>&1 ECHO Resetting Data Usage ECHO Y | del /f /q "C:\Windows\System32\sru\*.*" > nul ECHO. ECHO Restarting Diagnostic Policy Service ECHO. net start DPS > NUL 2>&1 ECHO Data Usage was Reset to 0 ECHO. ECHO Closing in 5 Seconds.... timeout /t 5 /nobreak >nul 2>&1 exit :no exit
So is the failure you previously experienced resolved with this script? I'm updating the whole script at this moment to add several features.