Wrapper for _winreg

Fred Gansevles gansevle at ewi.utwente.nl
Mon Apr 7 15:59:35 EDT 2003


Hi,

I've written a wrapper for _winreg which, IMHO, makes registry access in
Windows trivial.
I looked at other approaches and wrote several of my own (only for internal
use) but this time I think this approach is usable for more than just my
own tinkering.

The main goal is to simplify both the substring notation for registry keys
an the access to registry data.

For example, to list the nameservers on a WindowsXP machine, the following
code snippet can be used:

        def NameServers():
            from reg import Keys, Value, HKLM
            Services = ["SYSTEM", "CurrentControlSet", "Services"]
            Interfaces = [Services, "Tcpip", "Parameters", "Interfaces"]
            return [Value(HKLM, [Interfaces, interface], "NameServer")
                        for interface in Keys(HKLM, Interfaces)
                   ]

As you can see, you don't need to open a number of keys, this is done in the
module for you so 'one-shot' access to a part of the registry is simple.

Another example: find the proxyserver in the registry (from urllib.py)

            Settings = Key(HKCU, ["Software", "Microsoft", "Windows",
                                   "CurrentVersion", "Internet Settings"]
            if Value(Settings, name = "ProxyEnable"):
                proxyServer = str(Value(Settings, name = "ProxyServer"))

Here it is more efficient to pre-open a key since more than one value in the
key is referenced.


The complete module is located at 

        http://wwwhome.cs.utwente.nl/~gansevle/python/reg.py

The module is 'mildly' documented so it should be usable right away.

If anyone finds this module usefull, please drop me a line at
gansevle at ewi.utwente.nl








More information about the Python-list mailing list