# -*- coding: utf-8 -*- from setuphelpers import * import winreg uninstallkey = [] PROFILE = 100 REG_PATH = ( r'SOFTWARE\Microsoft\Windows\CurrentVersion' r'\Explorer\VolumeCaches' ) CATEGORIES = { 'Temporary Files', 'Thumbnail Cache', 'Delivery Optimization Files', } FLAG = 'StateFlags{:04d}'.format(PROFILE) def get_categories(): with reg_openkey_noredir( winreg.HKEY_LOCAL_MACHINE, REG_PATH ) as root: categories = [] index = 0 while True: try: categories.append(winreg.EnumKey(root, index)) index += 1 except OSError: break return categories def install(): available = get_categories() for category in available: path = REG_PATH + '\\' + category with reg_openkey_noredir( winreg.HKEY_LOCAL_MACHINE, path, sam=winreg.KEY_SET_VALUE ) as key: value = 2 if category in CATEGORIES else 0 reg_setvalue( key, FLAG, value, type=winreg.REG_DWORD ) if category in CATEGORIES: print('Enabled: {}'.format(category)) missing = CATEGORIES - set(available) if missing: print('Unavailable categories: {}'.format(missing)) # Execution silencieuse du profil run('cleanmgr.exe /sagerun:{}'.format(PROFILE), timeout=3600) def uninstall(): for category in get_categories(): path = REG_PATH + '\\' + category with reg_openkey_noredir( winreg.HKEY_LOCAL_MACHINE, path, sam=winreg.KEY_SET_VALUE ) as key: try: winreg.DeleteValue(key, FLAG) except FileNotFoundError: pass