Iterating over items in the registry

Fred Gansevles gansevle at cs.utwente.nl
Mon May 8 10:46:09 EDT 2000


In article <2B1262E83448D211AE4B00A0C9D61B03BA7335 at msgeuro1.creo.be>,
  Pieter Claerhout <PClaerhout at CREO.BE> wrote:
> Hello all,
>
> is there a way to iterate over keys in the registry? I want to scan
the
> contents of the key HKLM\HARDWARE\DEVICEMAP\Scsi to find info
> about all connected scsi hardware. I want to use this under NT. Is
this
> 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:
         try:
             sid = RegEnumKey (hkey, i)
             key = RegOpenKey (hkey, sid)
             path, kind = RegQueryValueEx (key, "ProfileImagePath")
             RegCloseKey (key)
             if ExpandEnvironmentStrings (path) == USERPROFILE:
                 i = -1
             else:
                 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 Deja.com http://www.deja.com/
Before you buy.



More information about the Python-list mailing list