The winreg entry of a python is looped through a sub-key

Source: Internet
Author: User
Tags python script

Python winreg items are looped through a subkey



Python winreg
I was able to retrieve 5 sub keys from the code under my Windows 7 Machine registry hive "HKEY_LOCAL_MACHINE".

from _winreg import *try: i = 0 while True:  subkey = EnumKey(HKEY_LOCAL_MACHINE, i)  print subkey  i += 1except WindowsError: pass

My question is, how do I base these buttons again? I want to finally list all the keys in software \ \ MICROSOFT \ \ Windows nt \ currentversion \ \ networklist \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ In the answer priority I ran my machine on the captcha, although it didn't make a mistake when it didn't produce the result.

from _winreg import *aReg = ConnectRegistry(None,HKEY_LOCAL_MACHINE)aKey = OpenKey(aReg, r"SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkList\Signatures\Unmanaged")for i in range(1024): try:  keyname = EnumKey(aKey, i)  asubkey = OpenKey(aKey, keyname)  val = QueryValueEx(asubkey, "Description")  print val except WindowsError:  break

À registry Editor or register query shows 6 values in that folder, but I can't get a Python script for these six.
This address: codego.net/8981951/
--------------------------------------------------------------------------------------------------------------- ----------
1. Do you have a job like this?

import _winregdef subkeys(key): i = 0 while True:  try:   subkey = _winreg.EnumKey(key, i)   yield subkey   i+=1  except WindowsError:   breakdef traverse_registry_tree(key=_winreg.HKEY_LOCAL_MACHINE, tabs=0): for k in subkeys(key):  print ‘\t‘*tabs + str(k)  traverse_registry_tree(k, tabs+1)


2. I do not have a registry key search, but the following code will list all subkeys in HKEY_LOCAL_MACHINE \ \ Software. I think that if you change the value of the Keyval string into your directory, it will work. The try ... except whole is such that EnumKey will fail. I didn't do it as a loop I don't know how to akey the right length.

keyVal = r"Software"aKey = OpenKey(HKEY_LOCAL_MACHINE, keyVal, 0, KEY_ALL_ACCESS)try: i = 0 while True:  asubkey = EnumKey(aKey, i)  print(asubkey)  i += 1except WindowsError: pass


This article title: Python's winreg items are looped through a subkey
This address: codego.net/8981951/

The winreg entry of a python is looped through a sub-key

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.