[Tutor] Window Registry Access

Lloyd Kvam pythonTutor at venix.com
Wed Oct 27 23:29:40 CEST 2004


On Wed, 2004-10-27 at 16:19, Gooch, John wrote:
> I am attempting to read information from a remote registry using Python, but
> cannot find any examples of it in the Python/Activestate mailing list
> archives nor plain old Google.com. Can someone point out what I am doing
> wrong? 
You have backslash (\) characters in the string.  These are used in
Python (and many other languages) to handle special characters that are
otherwise hard to type directly.  For example \r is the carriage return
(enter) key.  To enter a literal backslash, you use a pair of them (\\).

The simpler alternative is to use a raw string.  By placing r before the
quote you can disable the special backslash processing.
r'SOFTWARE\Microsoft\Windows NT\CurrentVersion\WinLogon'+'\\' == 'SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\WinLogon\\'

NOTE that a raw string MUST NOT end with a backslash character!

> The below code is what I am using, and it errors on the 'successful='
> line, telling me I am giving it invalid parameters. The parameters I am
> unsure of are the first and last ones, as , once again, I can find no
> documentation as to what they should be in Python. 

Python is simply providing a means to use functions provided by
Microsoft.  You need to use the Microsoft documentation while making
allowances for the fact that the expected language is probably C++.

> ------------------------------
> Microsoft documentation says
> this->http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisd
> k/wmi/getstringvalue_method_in_class_stdregprov.asp
> uint32 GetStringValue(
>   uint32 hDefKey,
>   string sSubKeyName,
>   string sValueName,
>   string sValue
> );
> 
> -------------------------------
> 
> 
> My Code
> ----------------------
> wmiRegObj = win32com.client.GetObject(
> r'winmgmts://somesystem/root/default:StdRegProv')
> if wmiRegObj:
>    print "Successfully connected to registry"
>   successful = wmiRegObj.GetStringValue( 'HKEY_LOCAL_MACHINE',
> 'SOFTWARE\Microsoft\Windows NT\CurrentVersion\WinLogon\' ,
> 'DefaultUserName', username )   
>  
> 
> John A. Gooch
> Systems Administrator
> IT - Tools
> EchoStar Satellite L.L.C.
> 9601 S. Meridian Blvd.
> Englewood, CO  80112
> Desk: 720-514-5708 
> 
> 
> -----Original Message-----
> From: Christian Wyglendowski [mailto:Christian.Wyglendowski at greenville.edu] 
> Sent: Wednesday, October 27, 2004 8:32 AM
> To: Kent Johnson; Bill Mill
> Cc: tutor at python.org
> Subject: RE: [Tutor] Turning a "script" into an "application"
> 
> 
> Bill, Kent, Joe,
> 
> Thanks a lot for openly discussing the different approaches to my problem.
> With your help, I have gained some insight into the problem area that I am
> tackling, and that's what I was looking for.
> 
> The multiprocess socket/XMLRPC option is very exciting in that I could
> create a generic "sniffer server" that can talk with whatever client(s) I
> decide to create.
> 
> The all-in-one threaded option is tempting for a couple reasons:
> 	1.  I would like to get some experience with threads.
> 	2.  Overall, the architecture sounds less complex.
> 
> For the sake of flexibility, I am leaning towards the multiprocess option
> using XMLRPC.
> 
> Thanks again for the ideas/counter-ideas!
> 
> Christian
> http://www.dowski.com
> 
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
-- 
Lloyd Kvam
Venix Corp



More information about the Tutor mailing list