Win32 Registry Manipulation w/PythonWin?

Tim Daneliuk tundra at tundraware.com
Mon Jul 29 08:30:02 CEST 2002


Tim Daneliuk wrote:
> Does some kind soul out there happen to have a pointer to a 
> tutorial/examples on
> fiddling with the Win32 registry from PythonWin?
> 
> TIA,

Thanks to the many who followed up on this thread.  I now have a first-cut
of my MRU cleanup utility, but have a few further questions:

######################################################################################

from _winreg import *

mrulist = \
     ( \
     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\Excel\Recent Files", \
     r"Software\Microsoft\MediaPlayer\Player\RecentFileList", \
     )

reg  = ConnectRegistry(None,HKEY_CURRENT_USER)

for entry in mrulist:
     DeleteKey(reg, entry)
     CreateKey(reg, entry)

CloseKey(reg)

######################################################################################


This works fine for those programs that place their MRU list in a distinct
key just for that purpose, as the examples in 'mrulist' above do.

However, some programs place this information within a key that also holds
other information the program needs to do its job.  In this case, my approach -
nuking the whole key and then recreating an empty one - does not work because
I would also be wiping out the non-MRU stuff.

This is where I run into a problem.  I am having a dickens of a time figuring
out how to remove just a single value within a key.  I cannot seem to find
the magic that allows editing of the lowest level leaf nodes of a registry
entry on an individual basis.  If I try to treat them as *key* Python grumbles
something to the effect that it cannot find that file at the OpenKey call.
If I try to use DeleteValue, I get permission denied even though I am running
with Administrator privileges on a Win2K machine.

This may well be a lack of my understanding Windoze and the arcana of the
registry - I'm more of a Unix person - and not a Python problem at all.
In any case, help is appreciated as always.


TIA,
------------------------------------------------------------------------------
Tim Daneliuk
tundra at tundraware.com




More information about the Python-list mailing list