[Python-Dev] winreg

Thomas Heller thomas.heller@ion-tof.com
Tue, 27 Jun 2000 17:42:26 +0200


(Hopefully it is ok to use the reply-all button)

> ...
> My stance was that keys would always be created from keys, so you would
> start with
>
> HKEY_LOCAL_MACHINE.CreateKey("Software\Python")
>
> That mirrors the underlying API a little closer and reduces the number
> of functions to 0.
Good idea!
Maybe HKLM and so on should be provided as aliases.

> >
> >   DeleteKey (name [,recursive=0])
> >     If recursive is 0, deletes the named key if no subkeys exist.
> >     If there are subkeys an error is raised.
> >     If recursive is not 0, the named key is deleted
> >     including subkeys.
>
> I may or may not get around to implementing the recursive version. You
> have to be VERY CAREFUL when you test such a thing. :)
Someone (I don't remember who) mentioned in the discussion
about my proposal that one should use SHDeleteKey for recursive
deletion of keys. See the MSDN docs on RegDeleteKey for details.
Don't know if this is exposed by the lowlevel module.

>
> > If we change the name of the low level api module, we have to change
> > Distutils,
> > because it is used there. Maybe we would better use the high level api
then,
> > but there is still this 1.5 compatibility using the win32api module.
>
> The high level could probably be made compatible with 1.5 like this:
>
> try:
>     import _winreg
> except ImportError:
>     import win32api
>     winreg=win32api
Currently it goes like this, because win32api and winreg (which
will soon be _winreg) have slightly different apis, but it will
doubtlessly be solved:

try:
    import winreg
    _can_read_reg = 1
    hkey_mod = winreg

    RegOpenKeyEx = winreg.OpenKeyEx
    RegEnumKey = winreg.EnumKey
    RegEnumValue = winreg.EnumValue
    RegError = winreg.error

except ImportError:
    try:
        import win32api
        import win32con
        _can_read_reg = 1
        hkey_mod = win32con

        RegOpenKeyEx = win32api.RegOpenKeyEx
        RegEnumKey = win32api.RegEnumKey
        RegEnumValue = win32api.RegEnumValue
        RegError = win32api.error

    except ImportError:
        pass

Thomas