Python có thể truy cập Registry Windows nhờ module winreg. Ví dụ kết nối registry, mở khóa, liệt kê các khóa con.
Ví dụ
Mã Python:
import winreg
#connecting to key in registry
access_registry = winreg.ConnectRegistry(None,winreg.HKEY_LOCAL_MACHINE)
access_key = winreg.OpenKey(access_registry,r"SOFTWARE\Microsoft\Windows\CurrentVersion")
#accessing the key to open the registry directories under
for n in range(20):
try:
x =winreg.EnumKey(access_key,n)
print(x)
except:
break Đầu ra
Chạy mã cho kết quả:
ApplicationFrame AppModel Appx Audio Authentication AutoRotation BITS Casting ClosedCaptioning CloudExperienceHost Component Based Servicing …….. …..