Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Display Adapter Information from Registry?

Reply
Thread Tools

Display Adapter Information from Registry?

 
 
Omer Ahmad
Guest
Posts: n/a
 
      12-03-2004
Hi All,

I've been working with python for about 6 months now, and have been
very impressed with the size and scope of the libraries. I have,
however, run into a bit of a problem.

I discoverred Marc Hammonds PyWin32 extensions, (whcih are awesome)
and Tim Golden's WMI wrapper for accessing the Windows Management
Instrumentation (Win32_Classes) but now I have been asked to remove
these dependandcies and still obtain machine information from the
registry (Windows only of course) so that we do not have to ship any
extensions to Python with our commercial software.

I need to grab the following information:

CPU(s) Descriptions strings (for multiple processors) (found in
registry)
Display Adapter description string (found in registry)
Display Adapter Memory (found in registry)

What I'm having trouble with is to grab the DISPLAY ADAPTER version
using python and no Win32com client (i.e. pyWin32). I thought about
grabbing the file name of the driver from the registry and then
looking up the file and calculating the version number (by parsing the
binary) but this only works if i can find the file. I tried it out on
a few machines with different video adapters and thsi didn't prove to
be a reliable method.

Any suggestions? Please????

Omer Ahmad.

ps: here is the code i'm using right now (minus all the debug strings)


def main():
"""Retrieves Machine information from the registry"""

try:
hHardwareReg = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE,
"HARDWARE")
hDescriptionReg = _winreg.OpenKey(hHardwareReg, "DESCRIPTION")
hSystemReg = _winreg.OpenKey(hDescriptionReg, "SYSTEM")
hCentralProcessorReg = _winreg.OpenKey(hSystemReg,
"CentralProcessor")
nbProcessors = _winreg.QueryInfoKey(hCentralProcessorReg)[0]

for idxKey in range(nbProcessors):
#get a handle to the processor ID key
hProcessorIDReg = _winreg.OpenKey(hCentralProcessorReg,
str(idxKey))
processorDescription =
_winreg.QueryValueEx(hProcessorIDReg,"ProcessorNam eString")[0]
mhz = _winreg.QueryValueEx(hProcessorIDReg, "~MHz")[0]
print "Processor " + str(idxKey) + ": " +
string.lstrip(processorDescription) + " Clock Speed: " + str(mhz)

except WindowsError:
print "Cannot retrieve processor information from registry!"

#get handle to device map, reusing hardware handle

try:
hDeviceMapReg = _winreg.OpenKey(hHardwareReg, "DEVICEMAP")
hVideoReg = _winreg.OpenKey(hDeviceMapReg, "VIDEO")
VideoCardString =
_winreg.QueryValueEx(hVideoReg,"\Device\Video0")[0]
#Get Rid of Registry/Machine from the string
VideoCardStringSplit = VideoCardString.split("\\")
ClearnVideoCardString =
string.join(VideoCardStringSplit[3:], "\\")
#Go up one level for detailed
VideoCardStringRoot =
string.join(VideoCardStringSplit[3:len(VideoCardStringSplit)-1], "\\")

#Get the graphics card information
hVideoCardReg = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE,
ClearnVideoCardString)
VideoCardDescription = _winreg.QueryValueEx(hVideoCardReg,
"Device Description")[0]
VideoCardMemorySize = _winreg.QueryValueEx(hVideoCardReg,
"HardwareInformation.MemorySize")[0]

print "Graphics Card: " + VideoCardDescription
print "Memory: " +
str(struct.unpack('l',VideoCardMemorySize)[0])

except WindowsError:
print "Cannot Retrieve Graphics Card Name and Memory Size!"
 
Reply With Quote
 
 
 
 
Larry Bates
Guest
Posts: n/a
 
      12-03-2004
Let's see, there are tools that do what you want but you are
being told not use them? If you use py2exe to bundle up all
your commercial software (with extensions) and then Inno Setup
to create a setup.exe file for setting everything up, nobody
ever knows about Python, extensions, etc. This eliminates the
need to have Python (and any extensions) installed on the
target machines. I (and many others) do this for all my
Windows software that is to be distributed.

Hope information helps.
Larry Bates


Omer Ahmad wrote:
> Hi All,
>
> I've been working with python for about 6 months now, and have been
> very impressed with the size and scope of the libraries. I have,
> however, run into a bit of a problem.
>
> I discoverred Marc Hammonds PyWin32 extensions, (whcih are awesome)
> and Tim Golden's WMI wrapper for accessing the Windows Management
> Instrumentation (Win32_Classes) but now I have been asked to remove
> these dependandcies and still obtain machine information from the
> registry (Windows only of course) so that we do not have to ship any
> extensions to Python with our commercial software.
>
> I need to grab the following information:
>
> CPU(s) Descriptions strings (for multiple processors) (found in
> registry)
> Display Adapter description string (found in registry)
> Display Adapter Memory (found in registry)
>
> What I'm having trouble with is to grab the DISPLAY ADAPTER version
> using python and no Win32com client (i.e. pyWin32). I thought about
> grabbing the file name of the driver from the registry and then
> looking up the file and calculating the version number (by parsing the
> binary) but this only works if i can find the file. I tried it out on
> a few machines with different video adapters and thsi didn't prove to
> be a reliable method.
>
> Any suggestions? Please????
>
> Omer Ahmad.
>
> ps: here is the code i'm using right now (minus all the debug strings)
>
>
> def main():
> """Retrieves Machine information from the registry"""
>
> try:
> hHardwareReg = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE,
> "HARDWARE")
> hDescriptionReg = _winreg.OpenKey(hHardwareReg, "DESCRIPTION")
> hSystemReg = _winreg.OpenKey(hDescriptionReg, "SYSTEM")
> hCentralProcessorReg = _winreg.OpenKey(hSystemReg,
> "CentralProcessor")
> nbProcessors = _winreg.QueryInfoKey(hCentralProcessorReg)[0]
>
> for idxKey in range(nbProcessors):
> #get a handle to the processor ID key
> hProcessorIDReg = _winreg.OpenKey(hCentralProcessorReg,
> str(idxKey))
> processorDescription =
> _winreg.QueryValueEx(hProcessorIDReg,"ProcessorNam eString")[0]
> mhz = _winreg.QueryValueEx(hProcessorIDReg, "~MHz")[0]
> print "Processor " + str(idxKey) + ": " +
> string.lstrip(processorDescription) + " Clock Speed: " + str(mhz)
>
> except WindowsError:
> print "Cannot retrieve processor information from registry!"
>
> #get handle to device map, reusing hardware handle
>
> try:
> hDeviceMapReg = _winreg.OpenKey(hHardwareReg, "DEVICEMAP")
> hVideoReg = _winreg.OpenKey(hDeviceMapReg, "VIDEO")
> VideoCardString =
> _winreg.QueryValueEx(hVideoReg,"\Device\Video0")[0]
> #Get Rid of Registry/Machine from the string
> VideoCardStringSplit = VideoCardString.split("\\")
> ClearnVideoCardString =
> string.join(VideoCardStringSplit[3:], "\\")
> #Go up one level for detailed
> VideoCardStringRoot =
> string.join(VideoCardStringSplit[3:len(VideoCardStringSplit)-1], "\\")
>
> #Get the graphics card information
> hVideoCardReg = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE,
> ClearnVideoCardString)
> VideoCardDescription = _winreg.QueryValueEx(hVideoCardReg,
> "Device Description")[0]
> VideoCardMemorySize = _winreg.QueryValueEx(hVideoCardReg,
> "HardwareInformation.MemorySize")[0]
>
> print "Graphics Card: " + VideoCardDescription
> print "Memory: " +
> str(struct.unpack('l',VideoCardMemorySize)[0])
>
> except WindowsError:
> print "Cannot Retrieve Graphics Card Name and Memory Size!"

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
ExpressCard wireless adapter vs PC card wireless adapter =?Utf-8?B?a2V2aW5sYQ==?= Wireless Networking 6 12-21-2008 08:18 PM
2-FXS VoIP adapter versus 2-port FXO VoIP adapter? GS VOIP 5 04-19-2007 07:45 AM
I have one ASP.NET Page. It's for display customer information. Now I want this page to handle the function "Edit" and "Display", Is it possible? Benny Ng ASP .Net 1 01-04-2007 08:00 PM
Wireless Notebook Adapter - Linksys PCMCIA adapter Error Exception E06D7363 pattyjamas@hotmail.com Wireless Networking 0 02-21-2005 07:05 PM
Looking for lens adapter for Kodak DX6490 information. Info Digital Photography 8 11-21-2003 02:12 PM



Advertisments