Display Adapter Information from Registry?

Discussion in 'Python' started by Omer Ahmad, Dec 3, 2004.

  1. Omer Ahmad

    Omer Ahmad Guest

    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!"
     
    Omer Ahmad, Dec 3, 2004
    #1
    1. Advertising

  2. Omer Ahmad

    Larry Bates Guest

    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,"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!"
     
    Larry Bates, Dec 3, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. HK
    Replies:
    1
    Views:
    3,653
    Cowboy \(Gregory A. Beamer\)
    Apr 1, 2004
  2. Replies:
    0
    Views:
    759
  3. Leny
    Replies:
    3
    Views:
    16,940
    Daniel
    Feb 1, 2005
  4. Replies:
    0
    Views:
    1,609
  5. Collin Miller
    Replies:
    10
    Views:
    620
    Roger Pack
    Jul 9, 2010
Loading...

Share This Page