ASPN ActiveState Programmer Network  
ActiveState, a division of Sophos
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups
Submit Recipe
My Recipes

All Recipes
All Cookbooks


View by Category

Title: Example For winreg (1)
Submitter: Stephen Chappell (other recipes)
Last Updated: 2007/03/02
Version no: 1.1
Category: Shortcuts

 

Not Rated yet


Description:

The code presented below is a short example of how
to use winreg. This recipe prints out as much data
as possible about the user's registry. Hives are
specified as such before their representations.
Errors in opening keys are listed with the problem
key's name.

Source: Text Source

from winreg import *

def main():
    for hive in Registry():
        show_all(hive)

def show_all(key, level=0):
    if level:
        title(repr(key), level)
    else:
        title('HIVE ' + repr(key), level)
    for name in key.values:
        if name:
            point('%r = %r' % (name, key.values[name]), level + 1)
        else:
            point('(Default) = %r' % key.values[name], level + 1)
    for name in key.keys:
        try:
            show_all(key.keys[name], level + 1)
        except WindowsError:
            title('ERROR: %s' % name, level + 1)

def title(string, level):
    point(string, level)
    point('=' * len(string), level)

def point(string, level):
    print '  ' * level + string

if __name__ == '__main__':
    main()

Discussion:

This recipe demonstrates sample usage of the winreg module.
It is designed to give a representation of the registry's state.



Add comment

No comments.



Highest rated recipes:

1. A simple XML-RPC server

2. Web service accessible ...

3. IPy Notify

4. Changing return value ...

5. Quantum Superposition

6. Pickle objects under ...

7. Generalized delegates ...

8. Reorder a sequence (uses ...

9. Setting Win32 System ...

10. ObjectMerger




Privacy Policy | Email Opt-out | Feedback | Syndication
© 2006 ActiveState Software Inc. All rights reserved.