Windows 10 / 11 post WU installation cleanup script


Hey, folks,

Thanks to a lot of wonderful folks here, we've made mention in a previous Insider topic about cleanup steps that can be run after Windows Update performs a major version install.

Though these have been mentioned before by many, many people, it was this post by @IanMosley that started me on implementing this as an step to clean up both my main Windows installation and all the VMs I have for testing:


A few posts later, @geneo offered some good advice on how to streamline that set of commands in this post:


Which, eventually, led me to mentioning that I had put them all in a batch file to run after major WU installs:


Thus far I've just been right clicking the file and selecting Run as Administrator to run it - not all that hard. But, today, I went in search of a self-elevation script for batch files so I can just double click the file and let it do its thing.

I found a good thread at Stack Overflow that has a few methods mentioned, including direct self-elevation, elevation via WSH, via VBScripting, and even via Powershell. I tested several ones, and found that this particular script works best and is no nonsense and has no fuss:


I've also added a pause command at the end so that the window remains on screen after completing so you can see the results, and a simple keypress will close it out.

So, here is the code as I'm using it now:

Batch:
:: Elevation script from StackOverflow
:: https://stackoverflow.com/a/28467343

:: Begin Elevation script

@ECHO OFF
setlocal EnableDelayedExpansion

::net file to test privileges, 1>NUL redirects output, 2>NUL redirects errors
NET FILE 1>NUL 2>NUL
if '%errorlevel%' == '0' ( goto START ) else ( goto getPrivileges )

:getPrivileges
if '%1'=='ELEV' ( goto START )

set "batchPath=%~f0"
set "batchArgs=ELEV"

::Add quotes to the batch path, if needed
set "script=%0"
set script=%script:"=%
IF '%0'=='!script!' ( GOTO PathQuotesDone )
    set "batchPath=""%batchPath%"""
:PathQuotesDone

::Add quotes to the arguments, if needed.
:ArgLoop
IF '%1'=='' ( GOTO EndArgLoop ) else ( GOTO AddArg )
    :AddArg
    set "arg=%1"
    set arg=%arg:"=%
    IF '%1'=='!arg!' ( GOTO NoQuotes )
        set "batchArgs=%batchArgs% "%1""
        GOTO QuotesDone
        :NoQuotes
        set "batchArgs=%batchArgs% %1"
    :QuotesDone
    shift
    GOTO ArgLoop
:EndArgLoop

::Create and run the vb script to elevate the batch file
ECHO Set UAC = CreateObject^("Shell.Application"^) > "%temp%\OEgetPrivileges.vbs"
ECHO UAC.ShellExecute "cmd", "/c ""!batchPath! !batchArgs!""", "", "runas", 1 >> "%temp%\OEgetPrivileges.vbs"
"%temp%\OEgetPrivileges.vbs"
exit /B

:START
::Remove the elevation tag and set the correct working directory
IF '%1'=='ELEV' ( shift /1 )
cd /d %~dp0

::Do your adminy thing here...

:: End Elevation Script
:: Begin cleanup script

start /B /wait rundll32.exe pnpclean.dll,RunDLL_PnpClean /drivers/maxclean
start /B /wait dism /Online /Cleanup-Image /CheckHealth
start /B /wait sfc /scannow
start /B /wait dism /Online /Cleanup-Image /RestoreHealth
start /B /wait dism /online /Cleanup-Image /Startcomponentcleanup /resetbase

pause

You can copy the contents and save it to a file with a .BAT extension and it should work just fine, tested across Windows 10 and Windows 10 Insider Preview, plus Windows 11 (RTM, Release Preview, Beta, Dev and Canary current builds).

If you'd rather just download the batch file, here you go.

Download

Enjoy!

P.S. - if you have any suggestions on improving it / adding more functionality / expanding the scope of the cleanup, feel free to comment below!
 
Windows Build/Version
Windows 10 / Windows 11

Attachments

Last edited by a moderator:
I was directed in one of my forum help posts to run this script. Can anyone tell me what it does? Either I am out of the loop, or I missed what the script is supposed to do.

Thanks, Jesse

It basically just runs these commands but automated and in succession, Jesse.

/drivers/maxclean
dism /Online /Cleanup-Image /CheckHealh
sfc /scannow
dism /Online /Cleanup-Image /RestoreHealth
dism /online /Cleanup-Image /Startcomponentcleanup /resetbase

So, to clarify a little more, the script I have linked in the first post is my attempt to collate all of the usual steps many of use power, pro and expert users here at Eleven FOrum (11F) use to help clean up our systems after a major update to Windows, specifically those line items that @antspants mentions. I did a lot of research and evaluated various ways to make the script more automated, and settled on a way that the batch file run and automatically elevated its own privileges so the commands can be run without unnecessary (and repeated) UAC elevation prompts, or potentially failing because of a lack of elevation in the first place.

In post #47 (<-- clickable link) above, though, I link to a utility that can run all of these commands with a bit more clarity, giving a small explanation of each, and while less automated than my script, it is, I feel, the superior approach to accomplishing these same steps that my script does, partially because of the independent windows with respective command output, as well as the ability to run other commands that are not included in the script that I compiled.

Your approach is probably the best way!

I removed another app called web experience something or other. It apparently controls the widget stuff which I don't use. Bofore the day was out, I noticed that windows had re-installed it.

I'm beginning to think this particular minion function really isn't useful.

I suppose it depends on the approach - but removing pre-installed Windows app does require a bit of research. As Garlin noted in post #54 above, one such example is one app the was renamed and a new app that was added using the old name lol. Whereas the old app was removable, the newer one is not, and you noted that it still showed up even after you tagged it for removal - quite possibly because Stefan's utility was still trying to remove the old one versus the new one.

I've played around in the part with removing things, but I've found that simply disabling most of them suffices for me, and it's a lot less hassle in the long run, particularly when

1. I tend to cleanly install Windows 2-3 times a year, and
2. Windows can pull things like the above-noted app rename and replace, potentially rendering pre-written scripts (at least partially) useless, unless you are made aware of such changes in newer builds and adjust accordingly.

It's already so much of a headache to maintain such a script because of that second point, and since I run multiple VMs of various Windows 10 and Windows 11 versions, I've resorted to using Stefan's utility for everything my script can do and basically nothing else.
 

My Computers

System One System Two

  • OS
    Windows 11 23H2 Current build
    Computer type
    PC/Desktop
    Manufacturer/Model
    HomeBrew
    CPU
    AMD Ryzen 9 3950X
    Motherboard
    MSI MEG X570 GODLIKE
    Memory
    4 * 32 GB - Corsair Vengeance 3600 MHz
    Graphics Card(s)
    EVGA GeForce RTX 3080 Ti XC3 ULTRA GAMING (12G-P5-3955-KR)
    Sound Card
    Realtek® ALC1220 Codec
    Monitor(s) Displays
    2x Eve Spectrum ES07D03 4K Gaming Monitor (Matte) | Eve Spectrum ES07DC9 4K Gaming Monitor (Glossy)
    Screen Resolution
    3x 3840 x 2160
    Hard Drives
    3x Samsung 980 Pro NVMe PCIe 4 M.2 2 TB SSD (MZ-V8P2T0B/AM) } 3x Sabrent Rocket NVMe 4.0 1 TB SSD (USB)
    PSU
    PC Power & Cooling’s Silencer Series 1050 Watt, 80 Plus Platinum
    Case
    Fractal Design Define 7 XL Dark ATX Full Tower Case
    Cooling
    Arctic Liquid Freezer III 420 RGB + Air 3x 140mm case fans (pull front) + 1x 120 mm (push back) and 1 x 120 mm (pull bottom)
    Keyboard
    SteelSeries Apex Pro Wired Gaming Keyboard
    Mouse
    Logitech MX Master 3S | MX Master 3 for Business
    Internet Speed
    AT&T LightSpeed Gigabit Duplex Ftth
    Browser
    Nightly (default) + Firefox (stable), Chrome, Edge , Arc
    Antivirus
    Defender + MB 5 Beta
  • Operating System
    ChromeOS Flex Dev Channel (current)
    Computer type
    Laptop
    Manufacturer/Model
    Dell Latitude E5470
    CPU
    Intel(R) Core(TM) i5-6300U CPU @ 2.40GHz, 2501 Mhz, 2 Core(s), 4 Logical Processor(s)
    Motherboard
    Dell
    Memory
    16 GB
    Graphics card(s)
    Intel(R) HD Graphics 520
    Sound Card
    Intel(R) HD Graphics 520 + RealTek Audio
    Monitor(s) Displays
    Dell laptop display 15"
    Screen Resolution
    1920 * 1080
    Hard Drives
    Toshiba 128GB M.2 22300 drive
    INTEL Cherryville 520 Series SSDSC2CW180A 180 GB SATA III SSD
    PSU
    Dell
    Case
    Dell
    Cooling
    Dell
    Mouse
    Logitech MX Master 3S (shared w. Sys 1) | Dell TouchPad
    Keyboard
    Dell
    Internet Speed
    AT&T LightSpeed Gigabit Duplex Ftth
Just some input about the script:

1) rundll32.exe pnpclean.dll,RunDLL_PnpClean /drivers/maxclean
which when I did a search to figure out what it does before reading beyond the post #1, it can have bad consequences as seen here:

2) dism /online /Cleanup-Image /Startcomponentcleanup /resetbase

A few days ago when I had the Error 6824, I was reading about /resetbase and according to post #2 in this thread:
/resetbase has been disabled and it does more harm than good but /resetbase is ignored regardless.
Comment #26 in the current thread actually tells what /resetbase does in the "Warning" section.
 

My Computer

System One

  • OS
    Windows XP/7/8/8.1/10/11, Linux, Android, FreeBSD Unix
    Computer type
    Laptop
    Manufacturer/Model
    Dell XPS 15 9570
    CPU
    Intel® Core™ i7-8750H 8th Gen Processor 2.2Ghz up to 4.1Ghz
    Motherboard
    Dell XPS 15 9570
    Memory
    32GB using 2x16GB modules
    Graphics Card(s)
    Intel UHD 630 & NVIDIA GeForce GTX 1050 Ti with 4GB DDR5
    Sound Card
    Realtek ALC3266-CG
    Monitor(s) Displays
    15.6" 4K Touch UltraHD 3840x2160 made by Sharp
    Screen Resolution
    3840x2160
    Hard Drives
    Toshiba KXG60ZNV1T02 NVMe 1024GB/1TB SSD
    PSU
    Dell XPS 15 9570
    Case
    Dell XPS 15 9570
    Cooling
    Stock
    Keyboard
    Stock
    Mouse
    SwitftPoint ProPoint
    Internet Speed
    Comcast/XFinity 1.44Gbps/42.5Mbps
    Browser
    Microsoft EDGE (Chromium based) & Google Chrome
    Antivirus
    Windows Defender that came with Windows
I downloaded your script, but at this line in the script, dism /online /Cleanup-Image /Startcomponentcleanup /resetbase, I get this error at 23%:
Error: 6824 - The operation cannot be performed because another transaction depends on this property not changing.
What to do??
That has nothing to do with the script or the build of Windows you are running as others had mentioned when responding to you and also, /resetbase has nothing to do with it as it's ignored and disabled by Windows .

I had the same issue two days ago and the solution is mentioned in my post here with full credits to @Bree who along with others experienced the same problem over a year ago:
 
Last edited:

My Computer

System One

  • OS
    Windows XP/7/8/8.1/10/11, Linux, Android, FreeBSD Unix
    Computer type
    Laptop
    Manufacturer/Model
    Dell XPS 15 9570
    CPU
    Intel® Core™ i7-8750H 8th Gen Processor 2.2Ghz up to 4.1Ghz
    Motherboard
    Dell XPS 15 9570
    Memory
    32GB using 2x16GB modules
    Graphics Card(s)
    Intel UHD 630 & NVIDIA GeForce GTX 1050 Ti with 4GB DDR5
    Sound Card
    Realtek ALC3266-CG
    Monitor(s) Displays
    15.6" 4K Touch UltraHD 3840x2160 made by Sharp
    Screen Resolution
    3840x2160
    Hard Drives
    Toshiba KXG60ZNV1T02 NVMe 1024GB/1TB SSD
    PSU
    Dell XPS 15 9570
    Case
    Dell XPS 15 9570
    Cooling
    Stock
    Keyboard
    Stock
    Mouse
    SwitftPoint ProPoint
    Internet Speed
    Comcast/XFinity 1.44Gbps/42.5Mbps
    Browser
    Microsoft EDGE (Chromium based) & Google Chrome
    Antivirus
    Windows Defender that came with Windows
Is it a good idea/recommended to run this after the update to 24H2 from 23H2 ? And if it is, should I be running all of the commands or ?
 

My Computers

System One System Two

  • OS
    Windows 11 Pro 24H2
    Computer type
    PC/Desktop
    Manufacturer/Model
    Myself
    CPU
    AMD 7950X3D
    Motherboard
    Asus ROG Crosshair X670E Gene
    Memory
    G.Skill Z5 Neo 2x32GB @ 6000CL30
    Graphics Card(s)
    MSI 4090 Gaming X Slim
    Monitor(s) Displays
    Dell Alienware AW3423DW
    Screen Resolution
    3440x1440
    Hard Drives
    1 x Samsung 990 Pro 2TB
    2 x Samsung 990 Pro 4TB
    1 x Samsung 870 QVO 8TB
    PSU
    Cooler Master V SFX 1300W
    Case
    Sliger Cerberus
    Cooling
    Noctua NH-D12L
    Keyboard
    Wooting Two HE
    Mouse
    Logitech G Pro Wireless
    Internet Speed
    1.6Gbps
    Browser
    DuckDuckGo
    Antivirus
    Kaspersky Premium
    Other Info
    Speakers: SoundBlaster Katana X v2
    Headphones: Audeze LCD-GX & AIAIAI TMA-2 Wireless+
    Camera: Logitech Brio
    Drawing Tablet: Wacom Intuos Pro M
    NAS: WD MyCloud
    PCIe MSI Herald-BE NCM865 WiFi 7
  • Operating System
    Windows 11 Pro 23H2
    Computer type
    PC/Desktop
    Manufacturer/Model
    Myself
    CPU
    AMD 5950X
    Motherboard
    Asus ROG Crosshair VIII Impact
    Graphics card(s)
    PNY GeForce RTX 3090 24GB XLR8 Gaming
    Monitor(s) Displays
    Asus ROG Swift PG35VQ
    Screen Resolution
    3440x1440
    Hard Drives
    Samsung 980 Pro 2TB
    PSU
    Corsair SF750
    Case
    Ncase M1 v6
    Cooling
    Custom loop
    Mouse
    Logitech G Pro Wireless
    Keyboard
    Wooting One
    Internet Speed
    1.6Gbps
    Antivirus
    Kapsersky Premium
    Other Info
    Soundblaster Katana X
Is it a good idea/recommended to run this after the update to 24H2 from 23H2 ? And if it is, should I be running all of the commands or ?

I run Virtual Machines of numerous Windows 11 builds, mostly the various Insider Preview builds, but I do have one bone stock Windows 11 23H2 VM and another Windows 11 24H2 bone stock VM.

I run this script (mainly through the app I mentioned in post #47) on all of them. it's caught a few issues here and there along the way, early on, so for that reason alone I highly suggest doing this every time there is a massive update like changing the build version (23H2 --> 24H2) but even when there are simple build version changes (26100.2859 --> 26100.3025, as an example).

So, long story short - yes, it is always worth it to run these steps. I even run them on my main machine that is running 24H2.

Since you're asking specifically for the major update, it really is worth your while to run all of the steps.

@Almighty1 mentions a few posts up that the driver cleaning might cause issues, and resetbase has been ... relegated to being ignored.

So, these are the commands you'll want.

Batch:
dism /Online /Cleanup-Image /CheckHealth
dism /Online /Cleanup-Image /RestoreHealth
sfc /scannow

Technically, you don't even need to run the first one, so these two should be good enough:

Batch:
dism /Online /Cleanup-Image /RestoreHealth
sfc /scannow
 

My Computers

System One System Two

  • OS
    Windows 11 23H2 Current build
    Computer type
    PC/Desktop
    Manufacturer/Model
    HomeBrew
    CPU
    AMD Ryzen 9 3950X
    Motherboard
    MSI MEG X570 GODLIKE
    Memory
    4 * 32 GB - Corsair Vengeance 3600 MHz
    Graphics Card(s)
    EVGA GeForce RTX 3080 Ti XC3 ULTRA GAMING (12G-P5-3955-KR)
    Sound Card
    Realtek® ALC1220 Codec
    Monitor(s) Displays
    2x Eve Spectrum ES07D03 4K Gaming Monitor (Matte) | Eve Spectrum ES07DC9 4K Gaming Monitor (Glossy)
    Screen Resolution
    3x 3840 x 2160
    Hard Drives
    3x Samsung 980 Pro NVMe PCIe 4 M.2 2 TB SSD (MZ-V8P2T0B/AM) } 3x Sabrent Rocket NVMe 4.0 1 TB SSD (USB)
    PSU
    PC Power & Cooling’s Silencer Series 1050 Watt, 80 Plus Platinum
    Case
    Fractal Design Define 7 XL Dark ATX Full Tower Case
    Cooling
    Arctic Liquid Freezer III 420 RGB + Air 3x 140mm case fans (pull front) + 1x 120 mm (push back) and 1 x 120 mm (pull bottom)
    Keyboard
    SteelSeries Apex Pro Wired Gaming Keyboard
    Mouse
    Logitech MX Master 3S | MX Master 3 for Business
    Internet Speed
    AT&T LightSpeed Gigabit Duplex Ftth
    Browser
    Nightly (default) + Firefox (stable), Chrome, Edge , Arc
    Antivirus
    Defender + MB 5 Beta
  • Operating System
    ChromeOS Flex Dev Channel (current)
    Computer type
    Laptop
    Manufacturer/Model
    Dell Latitude E5470
    CPU
    Intel(R) Core(TM) i5-6300U CPU @ 2.40GHz, 2501 Mhz, 2 Core(s), 4 Logical Processor(s)
    Motherboard
    Dell
    Memory
    16 GB
    Graphics card(s)
    Intel(R) HD Graphics 520
    Sound Card
    Intel(R) HD Graphics 520 + RealTek Audio
    Monitor(s) Displays
    Dell laptop display 15"
    Screen Resolution
    1920 * 1080
    Hard Drives
    Toshiba 128GB M.2 22300 drive
    INTEL Cherryville 520 Series SSDSC2CW180A 180 GB SATA III SSD
    PSU
    Dell
    Case
    Dell
    Cooling
    Dell
    Mouse
    Logitech MX Master 3S (shared w. Sys 1) | Dell TouchPad
    Keyboard
    Dell
    Internet Speed
    AT&T LightSpeed Gigabit Duplex Ftth
Back
Top Bottom