title: Python code to read registry
body: <pre><code>from _winreg import *
  
  """print r"*** Reading from SOFTWARE\Microsoft\Windows\CurrentVersion\Run ***" """
  aReg = ConnectRegistry(None,HKEY_LOCAL_MACHINE)
  
  aKey = OpenKey(aReg, r"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall")
  for i in range(1024):
      try:
          asubkey=EnumKey(aKey,i)
          val=QueryValueEx(asubkey, "DisplayName")
          print val
      except EnvironmentError:
          break
  </code></pre>
  
  <p>Could anyone please correct the error...i just want to display the "DisplayName" within the subkeys of the key the HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall 
  This is the error i get..</p>
  
  <pre><code>Traceback (most recent call last):
    File "C:/Python25/ReadRegistry", line 10, in &lt;module&gt;
      val=QueryValueEx(asubkey, "DisplayName")
  TypeError: The object is not a PyHKEY object
  </code></pre>