read NT registry with python
Mike Fletcher
mfletch at tpresence.com
Wed Mar 15 10:13:48 EST 2000
WARNING:
I don't have a clue, this is just something I do, don't muck with
the registry evil and demons lurk beneath its surface, beware the corrupt
registry my son, for that is the path to peanut-butter-death... Haven't you
figured out that tree-in-forest question yet? You pay for these Zen lessons
by the hour you know...
Query example:
import win32api, string
# normally you would import these from win32con
HKEY_CLASSES_ROOT = 0x80000000
HKEY_CURRENT_USER = 0x80000001
REG_SZ= 1
INCLUDE_PATH_KEY =
"Software\\YourCompany\\YourProduct\\YourVersion\\YourVariable"
def getIncludePath():
''' Query registry for the include path '''
# download from registry here
try:
include = win32api.RegQueryValue(
HKEY_CURRENT_USER,
INCLUDE_PATH_KEY,
)
except win32api.error:
return None
Well, heed the warning in the file, but here's an example of set...
8<______________ mcf/utils/fileassociation.py _______________
### WARNING:
# I don't have a clue what I'm doing here!
import win32api
### Following is the "normal" approach,
### but it requires loading the entire win32con file (which is big)
### for two values...
##import win32con
##HKEY_CLASSES_ROOT = win32con.HKEY_CLASSES_ROOT
##REG_SZ = win32con.REG_SZ
### These are the hard-coded values, should work everywhere as far as I
know...
HKEY_CLASSES_ROOT = 0x80000000
REG_SZ= 1
def associate( extension, filetype, description="", commands=(), iconfile=""
):
'''Warning: I don't have a clue what I'm doing here!
extension -- extension including "." character, e.g. .proc
filetype -- formal name, no spaces allowed, e.g.
SkeletonBuilder.RulesFile
description -- human-readable description of the file type
commands -- sequence of (command, commandline), e.g. (("Open",
"someexe.exe %1"),)
iconfile -- optional default icon file for the filetype
'''
win32api.RegSetValue(
HKEY_CLASSES_ROOT,
extension,
REG_SZ,
filetype
)
if description:
win32api.RegSetValue(
HKEY_CLASSES_ROOT ,
filetype,
REG_SZ,
description
)
if iconfile:
win32api.RegSetValue(
HKEY_CLASSES_ROOT ,
"%(filetype)s\\DefaultIcon" % locals(),
REG_SZ,
iconfile
)
for (command, commandline) in commands:
win32api.RegSetValue(
HKEY_CLASSES_ROOT ,
"%(filetype)s\\Shell\\%(command)s" % locals(),
REG_SZ,
command,
)
win32api.RegSetValue(
HKEY_CLASSES_ROOT ,
"%(filetype)s\\Shell\\%(command)s\\Command" %
locals(),
REG_SZ,
commandline
)
-----Original Message-----
From: tiddlerdeja at my-deja.com [mailto:tiddlerdeja at my-deja.com]
Sent: Wednesday, March 15, 2000 9:44 AM
To: python-list at python.org
Subject: Re: read NT registry with python
Thanks for that, very much appreciated.
However, the second line:
win32api.RegQueryValueEx('AdminPassword')
I get an error with this:
>>> win32api.RegQueryValueEx('AdminPassword')
Traceback (innermost last):
File "<stdin>", line 1, in ?
TypeError: RegQueryValueEx requires exactly 2 arguments; 1 given
Any help with this is greatly appreciated.
p.s. I realise this is lame me asking this, but I'm new to registry
terms and I don't know what the second var should be.
In article <8anvhr$1756 at newton.cc.rl.ac.uk>,
"Richard Brodie" <R.Brodie at rl.ac.uk> wrote:
>
> <tiddlerdeja at my-deja.com> wrote in message news:8ansn6
$ece$1 at nnrp1.deja.com...
>
> > [HKEY_LOCAL_MACHINE\SOFTWARE\WOF]
> >
> > [HKEY_LOCAL_MACHINE\SOFTWARE\ABC\PlusSoftware]
> > "AdminPassword"="Admin"
>
> import win32api
> from win32con import *
>
> k=win32api.RegOpenKeyEx(HKEY_LOCAL_MACHINE,
> 'SOFTWARE\\ABC\\PlusSoftware',0,KEY_QUERY_VALUE)
>
> win32api.RegQueryValueEx('AdminPassword')
>
>
Sent via Deja.com http://www.deja.com/
Before you buy.
--
http://www.python.org/mailman/listinfo/python-list
More information about the Python-list
mailing list