get registry information in python

James J. Besemer jb at cascade-sys.com
Thu Aug 15 14:13:00 CEST 2002


Steven Nien wrote:

> Thank you for your reply. I know how to using win32api or _winreg get
> registry data. For example:

> But the code can't run remotely for Win9x. (Win9x must install remotereg
> from Win9x CD) So I try to use Microsoft Windows Management Instrumentation
> (WMI) to get registry and hardware information.

I don't know about any of the above remote stuff or how it
contributes to your problem.

> I find scripts from Microsoft MSDN. For example:

If you know how to use _winreg and win32api then you should be able
to transliterate the visual basic example to Python.

The only complication that I see is

    Set oRegistry = _
        GetObject("winmgmts:{ImpersonationLevel=Impersonate}//" & _
        HostName & "/root/default:StdRegProv")

Which I surmise tries to connect to a remote registry hive.

I have no experience with the above VB construct but

    win32api.RegConnectRegistry()
or
    _winreg.RegConnectRegistry()

should do same thing -- that is to connect you to a registry
on remote HostName.

The other gotcha: for ANY of this registry crap to work, you
(your program) must have the proper security permissions to
allow it to do whatever it's trying to do -- not just when you attach
to the hive but for each and every single step along the way.

Note that in addition to whatever global restrictions are in place,
you yourself can further restrict access at just about any point
along the way.  All the registry "open" functions have an optional
security mask parameter and the defaults aren't always what you
want.

I have no idea how Windows security works between the various
Win platforms and that could be a continuing source of grief for you.

Regards

--jb

--
James J. Besemer  503-280-0838 voice
http://cascade-sys.com  503-280-0375 fax
mailto:jb at cascade-sys.com






More information about the Python-list mailing list