# Clean up selected MRU cruft from Win32 Registry # Copyright (c) 2002, TundraWare Inc., All Rights Reserved # $Id: mruclean.py,v 1.6 2002/12/09 21:10:56 tundra Exp $ ############################################################################## # # # XX XX XX XXXXXX XX XX XXXX XX XX XXXX XX # # XX XX XXXX XX XX XXX XX XX XXX XX XX X XX # # XX XX XX XX XX XX XXXX XX XX XXXX XX XX XX # # XX X XX XX XX XXXXX XX XXXX XX XX XXXX XX XX # # XXXXXXX XXXXXX XX XX XX XXX XX XX XXX XX XXX XX # # XXX XXX XX XX XX XX XX XX XX XX XX XX XX # # XX XX XX XX XXX XX XX XX XXXX XX XX XXX X XX # # # # THIS SOFTWARE MODIFIES YOUR WINDOWS REGISTRY AND CAN CORRUPT OR # # OTHERWISE DAMAGE YOUR SYSTEM. DO ****NOT**** RUN THIS ON YOUR # # SYSTEM UNLESS: # # 1) YOU THOROUGHLY UNDERSTAND WHAT IS GOING ON IN # # THIS PROGRAM. # # 2) YOU HAVE VERIFIED THAT THE REGISTRY MODIFICATIONS IN # # THIS PROGRAM ARE APPROPRIATE FOR ***YOUR*** SYSTEM # # # ############################################################################## ############################################################ ### Imports ### ############################################################ from _winreg import * ############################################################ ### Constants & Literals ### ############################################################ #################### # Constants #################### FALSE = 0 == 1 # Booleans TRUE = not FALSE #################### # Literals #################### ############################################################ ### Data ### ############################################################ ##### ### These are keys at the lowest level of the registry that need ### cleaning. That is, these keys contain only values, no subkeys. ##### leafnodes = \ ( \ r"Software\Microsoft\Windows\CurrentVersion\Explorer\ComDlg32\LastVisitedMRU", \ r"Software\Microsoft\Windows\CurrentVersion\Applets\Wordpad\Recent File List", \ r"Software\Microsoft\Windows\CurrentVersion\Applets\Paint\Recent File List", \ r"Software\Microsoft\Office\9.0\PowerPoint\Recent File List", \ r"Software\Microsoft\Office\9.0\Common\Open Find\Microsoft Excel\Settings\Save As\File Name MRU", \ r"Software\Microsoft\Office\9.0\Excel\Recent Files", \ r"Software\Microsoft\MediaPlayer\Player\RecentFileList", \ ) ##### ### These are keys with subkeys that need cleaning. That is, ### each of the *subkeys* of each of these entries will be cleaned. ##### subkeys = \ ( \ r"Software\Microsoft\Windows\CurrentVersion\Explorer\ComDlg32\OpenSaveMRU", \ ) ############################################################ ### Supporting Functions ### ############################################################ ##### ### Initialize a key back to its empty state. ##### def CleanKey(reg, key): try: DeleteKey(reg, key) except: pass CreateKey(reg, key) ############################################################ ### Main Program ### ############################################################ ### Connect to the local registry reg = ConnectRegistry(None,HKEY_CURRENT_USER) ### Clean the leafnodes for entry in leafnodes: CleanKey(reg, entry) ### Clean the subkeys for sk in subkeys: k = OpenKey(reg, sk , 0, KEY_READ) for i in range(0,1024): try: CleanKey(reg, sk + "\\" + EnumKey(k,i)) except EnvironmentError: break CloseKey(k) ### Clean the special cases k = OpenKey(reg, r"Software\Microsoft\Photo Editor\3.0\Microsoft Photo Editor", 0, KEY_WRITE) for x in range(1,1024): try: DeleteValue(k, "LastFile"+str(x)) DeleteValue(k, "LastType"+str(x)) except: pass CloseKey(k) CloseKey(reg)