Display Adapter Information from Registry?

Omer Ahmad ahmado at gmail.com
Fri Dec 3 09:35:55 EST 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,"ProcessorNameString")[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!"



More information about the Python-list mailing list