Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>What about x86 on x64? <a href="http://docs.python.org/2/library/_winreg.html#bit-specific" rel="noreferrer">Use <em>64-bit Specific</em> Types</a></p> <p>What if there's more than 1024 sub-keys in "Uninstall"? <a href="http://docs.python.org/2/library/_winreg.html#_winreg.QueryInfoKey" rel="noreferrer">Use <em>_winreg.QueryInfoKey(key)</em></a></p> <p><strong>Python 2:</strong></p> <pre><code>import errno, os, _winreg proc_arch = os.environ['PROCESSOR_ARCHITECTURE'].lower() proc_arch64 = os.environ['PROCESSOR_ARCHITEW6432'].lower() if proc_arch == 'x86' and not proc_arch64: arch_keys = {0} elif proc_arch == 'x86' or proc_arch == 'amd64': arch_keys = {_winreg.KEY_WOW64_32KEY, _winreg.KEY_WOW64_64KEY} else: raise Exception("Unhandled arch: %s" % proc_arch) for arch_key in arch_keys: key = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, r"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall", 0, _winreg.KEY_READ | arch_key) for i in xrange(0, _winreg.QueryInfoKey(key)[0]): skey_name = _winreg.EnumKey(key, i) skey = _winreg.OpenKey(key, skey_name) try: print _winreg.QueryValueEx(skey, 'DisplayName')[0] except OSError as e: if e.errno == errno.ENOENT: # DisplayName doesn't exist in this skey pass finally: skey.Close() </code></pre> <p><strong>Python 3:</strong></p> <pre><code>import errno, os, winreg proc_arch = os.environ['PROCESSOR_ARCHITECTURE'].lower() proc_arch64 = os.environ['PROCESSOR_ARCHITEW6432'].lower() if proc_arch == 'x86' and not proc_arch64: arch_keys = {0} elif proc_arch == 'x86' or proc_arch == 'amd64': arch_keys = {winreg.KEY_WOW64_32KEY, winreg.KEY_WOW64_64KEY} else: raise Exception("Unhandled arch: %s" % proc_arch) for arch_key in arch_keys: key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, r"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall", 0, winreg.KEY_READ | arch_key) for i in range(0, winreg.QueryInfoKey(key)[0]): skey_name = winreg.EnumKey(key, i) skey = winreg.OpenKey(key, skey_name) try: print(winreg.QueryValueEx(skey, 'DisplayName')[0]) except OSError as e: if e.errno == errno.ENOENT: # DisplayName doesn't exist in this skey pass finally: skey.Close() </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload