from winreg import * #delete value def del_env(name): key = OpenKey(HKEY_CURRENT_USER, r"datngu", 0, KEY_ALL_ACCESS) DeleteValue(key, "1") CloseKey(key) #delete key def delete_registry_tree(root, subkey): try: hkey = OpenKey(root, subkey, access=KEY_ALL_ACCESS) except OSError: # subkey does not exist return while True: try: subsubkey = EnumKey(hkey, 0) except OSError: # no more subkeys break delete_registry_tree(hkey, subsubkey) CloseKey(hkey) DeleteKey(root, subkey) delete_registry_tree(HKEY_CURRENT_USER, "datngu") #get key registry = ConnectRegistry(None, HKEY_LOCAL_MACHINE) def openRegistryA(): rawKeyA = OpenKey(registry, "SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System") try: i = 0 while 1: name, value, type = EnumValue(rawKeyA, i) print(name, value) i += 1 except WindowsError: print("END") CloseKey(rawKeyA) #setkey #trong này có cả create key keyVal = r'Software\Microsoft\Internet Explorer\Main' try: key = OpenKey(HKEY_CURRENT_USER, keyVal, 0, KEY_ALL_ACCESS) except: key = CreateKey(HKEY_CURRENT_USER, keyVal) SetValueEx(key, "Start Page", 0, REG_SZ, "http://www.blog.pythonlibrary.org/") #arg 1 = key #arg 2 = name of the subkey #arg 4 = type #arg 5 = value to set CloseKey(key)