Iterating over items in the registry

Fred Gansevles gansevle at
Mon May 8 10:46:09 EDT 2000

In article <2B1262E83448D211AE4B00A0C9D61B03BA7335 at>,
  Pieter Claerhout <PClaerhout at CREO.BE> wrote:
> Hello all,
> is there a way to iterate over keys in the registry? I want to scan
> contents of the key HKLM\HARDWARE\DEVICEMAP\Scsi to find info
> about all connected scsi hardware. I want to use this under NT. Is
> the proper way to do it, or does anyone has a module who accomplish
> this for me?
Here is the code of a function that returns the SID of the currentely
loggedin user.
This function ius part of a bigger program, so probably it won't
on your system but it gives you an idea how to iterate over
Registrey Keys.

def get_sid ():
     hkey = RegOpenKey (HKEY_LOCAL_MACHINE, ProfileList)
     sid = None
     i = 0
     while i >= 0:
             sid = RegEnumKey (hkey, i)
             key = RegOpenKey (hkey, sid)
             path, kind = RegQueryValueEx (key, "ProfileImagePath")
             RegCloseKey (key)
             if ExpandEnvironmentStrings (path) == USERPROFILE:
                 i = -1
                 i = i + 1
         except error, why:
             log ('Searching for sid:', str(why))
             i = -1
     RegCloseKey (hkey)
     return sid

> Kind regards,
> Pieter
> Pieter Claerhout
> Application Support - CreoScitex Europe

----          Linux/Windows-NT/IntraNetware Administrator          ----
-- Whenever it sounds simple, I've probably missed something! ... Me --

Sent via
Before you buy.

More information about the Python-list mailing list