1709 - Removal of previous versions of Windows

From what I understand, Windows 10 1709 will keep your previous version of Windows in the \Windows.old folder for 10 days.

Some of our SSDs are pretty low on free space and I’d like to expedite this process. I tried a simple folder delete script on a test machine but after that failed and manually attempting the delete failed, I decided to post here to find out what other are doing.

Thank you,

Don

Disk Clean up will do it. I’m sure there are other methods as well; Power Shell probably being the best. Find the commands and automated it…then look to deploy via BF.

Check out the command line switches on Disk Clean Up.


That /AutoCleanup looks promising.
Perhaps something in action script like:
wait cmd.exe /c "c:\windows\system32\cleanmgr.exe /autoclean"

-jgo

1 Like

To get more detailed, you can save and load specific cleanmgr to save a profile, then restore it and run it unattended later. For example -

cleanmgr.exe /sageset:1
(go through the GUI and pick your settings)

Then export HKLM\software\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches.
Preserve only the values “StateFlags0010” values from each subkey.

Then you can create a Task to restore these values and run cleanmgr unattended.

warning: In my example, I’m running Windows Update cleanup, which removes uninstall files for Windows Updates. This goes though Component-Based Servicing at startup - your first reboot after running this may take longer than usual, and you don’t want to run this as a Policy else all of your startups will take longer

Here’s an example of my Task for this, but your settings may vary (and probably should - I wrote this for Win7):

action uses wow64 redirection false

delete __createfile
createfile until EOF_EOF_EOF
Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Active Setup Temp Folders]
"StateFlags0001"=dword:00000002

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Downloaded Program Files]
"StateFlags0001"=dword:00000002

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Internet Cache Files]
"StateFlags0001"=dword:00000002

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Memory Dump Files]
"StateFlags0001"=dword:00000002

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Offline Pages Files]
"StateFlags0001"=dword:00000002

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Old ChkDsk Files]
"StateFlags0001"=dword:00000002

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Previous Installations]
"StateFlags0001"=dword:00000002

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Recycle Bin]
"StateFlags0001"=dword:00000002

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Service Pack Cleanup]
"StateFlags0001"=dword:00000002

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Setup Log Files]
"StateFlags0001"=dword:00000002

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\System error memory dump files]
"StateFlags0001"=dword:00000002

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\System error minidump files]
"StateFlags0001"=dword:00000002

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Temporary Files]
"StateFlags0001"=dword:00000002

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Temporary Setup Files]
"StateFlags0001"=dword:00000002

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Thumbnail Cache]
"StateFlags0001"=dword:00000002

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Update Cleanup]
"StateFlags0001"=dword:00000002

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Upgrade Discarded Files]
"StateFlags0001"=dword:00000002

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Windows Error Reporting Archive Files]
"StateFlags0001"=dword:00000002

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Windows Error Reporting Queue Files]
"StateFlags0001"=dword:00000002

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Windows Error Reporting System Archive Files]
"StateFlags0001"=dword:00000002

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Windows Error Reporting System Queue Files]
"StateFlags0001"=dword:00000002

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Windows Upgrade Log Files]
"StateFlags0001"=dword:00000002
EOF_EOF_EOF

delete DiskCleanup.reg
move __createfile DiskCleanup.reg
waithidden regedit /s DiskCleanup.reg

continue if {exists file "cleanmgr.exe" of native system folder and exists file "cleanmgr.exe.mui" of folder "en-US" of native system folder}

// Run the Disk Cleanup Wizard using the imported settings
waithidden CleanMgr.exe /sagerun:1
3 Likes

I had played with this a while ago and I think I found that this would only work if it was run by user (not by system). The only reason I knew that, because the job will complete successfully, was that I was able to verify that it was actually doing anything.

Can you confirm that you run this as System and that it works?

It was definitely working for me in the Win7 days, but I stopped my policy action on it due to some unrelated problems. Since then I have bigger disks, and haven’t bothered with cleanup in a while.

So I tested this on Windows 10 (1803) and Windows 2016.

Here is what I found:

If you use cleanmgr.exe /setup or cleanmgr.exe /autoclean or cleanmgr.exe /verylowdiskspace this will run as system!

If you use a cleanmgr.exe /sagerun:1 or cleanmgr.exe /tuneup:1 it will run as system, but you will need to use @JasonWalker example above.

If you run the cleanmgr.exe /lowdisk the exe appears to hang waiting for input and the process of cleanmgr.exe will just sit there.

I feel like the @JasonWalker method is my preferred method for execution.

I find this to be fully automate-E-able!

-jgo

Both of these show a GUI; I suspect that would prevent the Action from finishing. The /autoclean seems like it would be the best in trying to clean up a drive of common space consumption (if it wasn’t for the dialog it presents when finished). But your testing went fine, finishing with a status of Complete?

This would probably work, as there is no GUI or final status. But in our environment, these locations are not common.

In looking at this on my newest windows 10 1803 device.

When I launch the cleanmgr.exe /setup or cleanmgr.exe /autoclean from a windows normal user I see a dialog that I need to close and I see cleanmgr.exe in process until I x out of the dialog.

When I launch the cleanmgr.exe /setup or cleanmgr.exe /autoclean as SYSTEM I see cleanmgr.exe in processes for a short time and then it disappears from processes. It appears to be doing it’s job. Although this may be a false positive in my lab. I am standing up a new device now.

-jgo

(thread resurrection)

I’ve found that cleaning up Windows Setup files works easily from BigFix as SYSTEM:

// Temporary Windows Installation Files
regset "[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Temporary Setup Files]" "StateFlags1337"=dword:00000002

// run cleanmgr with the flagged operations
waithidden {native system folder}\cleanmgr.exe /sagerun:1337

regdelete "[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Temporary Setup Files]" "StateFlags1337"

I’m working on getting Update Cleanup to work. So far it runs for a brief period, but exits quickly without having made a change. I have a feeling that something like this may be necessary:

waithidden {native native system folder}\cleanmgr.exe /setup /sagerun:1337

Update Cleanup runs quickly, but actually only schedules it to be run during bootup (it’ll go through a cycle that looks like “Applying Updates” and take a half hour).

Found that the hard way when I scheduled it to run daily.

Well THAT’S interesting! If you run it manually in the GUI it can take a very long time. I was expecting something similar.

Thanks!

Try a reboot after and see whether it’s still the case. I haven’t tried it since build 1607.

No joy on 1703. I can’t get Update Cleanup to work from BigFix – cleanmgr runs for a bit, exits with 0, and then I restart. But during the restart no changes are applied.

Maybe its interdependent on some other option?

Maybe I’ll just use /VERYLOWDISK and move on with my life.

Wow64 redirection? Regset64?

Hmmm, good idea. I had been trying those on prior cycles, but they didn’t seem to affect efficacy. I’ll give it another whirl. Thanks.

OK, this is interesting. If I have wow64 redirection disabled, and use regset64, then Update Cleanup runs on demand. That much is fine.

However, I can’t seem to mix Update Cleanup and Temporary Setup Files in the same SageSet. If I do, only Temporary Setup Files runs; Update Cleanup seems to never run, even on reboot.

Meanwhile, Temporary Setup Files runs just dandy without disabling wow64 redirection, and using just regset.

Weird. More testing!

1 Like

I know I know I’m late to the party but I’m planning on rolling out some Windows 10 1909 updates and want to cleanup the Windows.old folder. Were you able to get this to work ultimately?

Sorry @jgallas, but I don’t think I resolved this completely. It became easier to write a fixlet with relevance for windows.old, than then forcibly deletes it. :smiley:

-Andrew

After I posted this I tried the below action script and it seems to remove the Windows.old folder however I had to change the original command that @jasonwalker provided from waithidden to runhidden because it seemed to take a long time to run or would not exit:

action uses wow64 redirection false

delete __createfile
createfile until EOF_EOF_EOF
Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Previous Installations]
"StateFlags0001"=dword:00000002
EOF_EOF_EOF

delete DiskCleanup.reg
move __createfile DiskCleanup.reg
waithidden regedit /s DiskCleanup.reg

continue if {exists file "cleanmgr.exe" of native system folder and exists file "cleanmgr.exe.mui" of folder "en-US" of native system folder}

// Run the Disk Cleanup Wizard using the imported settings
runhidden CleanMgr.exe /sagerun:1
2 Likes