Scanning through Windows registry...

Unknown Hero unknown_hero007 at hotmail.com
Tue May 6 08:05:21 EDT 2008


Tim Golden wrote:
> In a spirit of teaching people to fish...
>
> ... If you put something like "Python windows registry" into Google, you
> get quite a few hits, the top one of which is probably pointing to the stdlib
> _winreg module, but several others point towards wrapper classes, modules
> etc. which provide a simpler or at least a different interface to the registry.
>
> Have a look at those and see if you can't work out what to do.
>
> TJG

The first link which points to the Python documentation for the
_winreg module I already checked, even before coming here. I am
wondering how I should do the loop I need (go through
HKEY_LOCAL_MACHINE and read one subkey at a time, if it contains this
'foo' then change it into 'moo'). As I already said, I am by no means
an expert in Python (heck, I learned the basics only a month ago).
However, I am willing to learn.

Also my prior experience with the Windows registry is mostly by the
Registry Editor shipped with Windows. While I do understand what keys,
values and hives are, I do not have a great experience in the others.

If it's not too much to ask, maybe someone (who is much better than
me) could make a code snippet that reads a certain hive and replaces
values that are predetermined (preferably variables, not arguments if
possible).

If that's out of the question, at least push me gently into the right
direction.

So basically I am looking for these things:

1) Read one subkey from HKEY_LOCAL_MACHINE at a time (I think
QueryValueEx() is needed here)
2) Check if said subkey contains some predetermined string (like 'foo'
here)
3) If the above applies, change the value into another predetermined
string (like 'moo' here)


Also, how should I determine the length of the loop? I personally am
too fond of the for loop, but if I need to use, like, while, then so
be it.

Thanks in advance.



More information about the Python-list mailing list