1709 - Removal of previous versions of Windows

I have been able to get the WIndows.old a few different ways but “cleanmgr.exe” never properly terminates. This leaves the action running indefinitely. Using “runhidden” helps but proceeds to other steps in the action script too quickly. Thanks to a suggestion by @JasonWalker on a different post, we finally have a working solution. Below is my action script to run Disk Cleanup for “Previous Installations”.

action uses wow64 redirection false
    
parameter "StartTime"="{now}"

delete __createfile
delete regadd.reg

createfile until @end_create_reg_file
Windows Registry Editor Version 5.00

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

move __createfile regadd.reg
waithidden regedit /s regadd.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}

runhidden {native system folder}\cleanmgr.exe /sagerun:3005

pause while {exists processes whose (name of it = "cleanmgr.exe" and ppid of it = pid of service "BESClient") AND (now - (parameter "StartTime" as time) < 30 * minute)}
if {exists  processes whose (name of it = "cleanmgr.exe" and ppid of it = pid of service "BESClient")}
parameter "TimeoutReached"="True"
waithidden taskkill.exe {concatenation of ("/PID " & it as string & " ") of ids of processes whose (name of it = "cleanmgr.exe" and ppid of it = pid of service "BESClient")} /T /F
else
parameter "TimeoutReached"="False"
endif

delete __createfile
delete regdelete.reg

createfile until @end_create_reg_file
Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Previous Installations]
"StateFlags3005"=-
@end_create_reg_file

move __createfile regdelete.reg
waithidden regedit /s "regdelete.reg"
4 Likes