Page 1 of 1

Windows 10 cleanup and upgrade

Published: July 21, 2020 - 10:32 AM
by Mathieu
WAPT 1.8.2.7269
Server OS: Debian
OS DEV: Windows 10

Good morning,

I just updated my Windows10 upgrade package to v2004 and everything works perfectly.

I wanted to know if anyone had a solution via WAPT to clean up the residues from the update installation.

Because after installation I find myself with 16.3GB of space for temporary files "Previous Windows installations" which I would like to delete to free up space and put it in the audit section.

I found this which works, but not silently:

Code: Select all

New-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Temporary Setup Files' -PropertyType 'DWORD' -Force -Name 'StateFlags1337' -Value 0x2
New-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Previous Installations' -PropertyType 'DWORD' -Force -Name 'StateFlags1337' -Value 0x2
cleanmgr.exe /SAGERUN:1337
I also noticed that the windows10-upgrade package in the audit section was not working because it did not delete the "Windows Upgrade" folder.

By adding the variable upgrade_path = makepath(systemdrive,'WindowsUpgrade') in def audit and removing the try, the folder is deleted correctly.

Here is my modification:

Code: Select all

def audit():
    # Declaring specific app values
    package_version = control.version.split('-')[0]
    latest_version = package_version
    upgrade_path = makepath(systemdrive,'WindowsUpgrade')

    if Version(windows_version()) < Version(latest_version):
        print('Windows Upgrade has not succeed')
        return 'ERROR'
    elif isdir(upgrade_path):
        print('Windows %s already up-to-date' % windows_version())
        print('Cleanup as upgrade suceeded..')
        print('remove WindowsUpgrade')
        remove_tree(upgrade_path)
    else:
        print('Windows %s already up-to-date' % windows_version())
        return 'OK'
Thank you

Re: Cleaning windows10-upgrade

Published: August 14, 2020 - 08:48
by Mathieu
Good morning,

Back from vacation, I'm getting back to the topic of cleaning up Windows 10 upgrades

I'm using the solution Simon gave me, but I'm having a problem: the Windows.old folder isn't being deleted, even though the permissions modification commands work whether I'm running as administrator or system

Do you have any leads?

Code: Select all

def install():
    package_version = control.version.split('-')[0]
    latest_version = package_version
    update_package_old = makepath(systemdrive,'Windows.old')

    if Version(windows_version()) < Version(latest_version):
        print('Windows Upgrade has not succeed')
        return 'ERROR'
    elif isdir(update_package_old):
        print('Windows %s already up-to-date' % windows_version())
        print('remove Windows_old')
        print('Changement proprietaire')
        run_powershell('takeown /F C:\Windows.old\* /R /A /D O')
        print('Modification droits')
        run_powershell('cacls c:\Windows.old\*.* /t /grant administrators:f')
        print('Supression Windows.old')
        run('rmdir /s /q c:\Windows.old')
        print('Cleanup as upgrade suceeded..')

    else:
        print('Windows %s already up-to-date' % windows_version())
        print('Cleanup as upgrade suceeded..')
        return 'OK'

Re: Cleaning windows10-upgrade

Published: August 14, 2020 - 11:39
by Mathieu
The commands work manually if you check "Replace all permission entries for child objects," which I can't find in the command prompt

Re: Cleaning windows10-upgrade

Published: August 19, 2020 - 1:32 PM
by nliaudat
To add inheritance:

Code: Select all

  iCACLS.exe /inheritance:e|d|r
          e - Enable inheritance
          d - Disable inheritance and copy the ACEs 
          r - Remove all inherited ACEs
Details below viewtopic.php?f=9&t=2439

Re: Cleaning windows10-upgrade

Published: August 26, 2020 - 11:09 AM
by nliaudat

Code: Select all

    run_notfatal('RD /S /Q "C:\$Windows.~BT"')
    run_notfatal('RD /S /Q "C:\$Windows.~WS"')
    run_notfatal('RD /S /Q "C:\$GetCurrent"')
    run_notfatal('RD /S /Q "C:\$WinREAgent"')
    run_notfatal('RD /S /Q "C:\update_win10.log"')
    run_notfatal('RD /S /Q "C:\Windows.old"')
    run_notfatal('RD /S /Q "C:\Windows10Upgrade"')
    run_notfatal('RD /S /Q "C:\WindowsUpgrade"')
Works perfectly for me, without changing the permissions.

Re: Cleaning windows10-upgrade

Published: August 29, 2020 - 12:28
by Mathieu
I tried your commands.

I still have the Windows.old folder.

I can't find the right commands to properly clean it up after the upgrade.

Re: Cleaning windows10-upgrade

Published: August 31, 2020 - 12:25
by Jonathan K.
Hello,

just a thought, have you considered a PowerShell script?

Re: Cleaning windows10-upgrade

Published: September 1, 2020 - 11:12 AM
by nliaudat
This is simply a permissions issue. See the thread on iCACLS.exe: viewtopic.php?f=9&t=2439

Re: Cleaning windows10-upgrade

Published: September 1, 2020 - 11:27 AM
by nliaudat

Code: Select all

takeown /F "C:\Windows.old" /A /R /D Y
icacls "C:\Windows.old" /grant *S-1-5-32-544:F /T /C /Q
RD /S /Q "C:\Windows.old"