Display Adapter Information from Registry?

O

Omer Ahmad

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!"
 
L

Larry Bates

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 said:
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!"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,152
Latest member
LorettaGur
Top