要实现这个需求,你可以使用以下步骤编写Python脚本:

  1. 导入必要的模块:
import tkinter as tk
import winreg
  1. 创建一个函数来读取注册表中的记录信息:
def read_known_devices():
    key_path = r"SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\AutoplayHandlers\KnownDevices"
    key = winreg.OpenKey(winreg.HKEY_CURRENT_USER, key_path)
    known_devices = []
    try:
        i = 0
        while True:
            sub_key_name = winreg.EnumKey(key, i)
            sub_key_path = key_path + "\\" + sub_key_name
            sub_key = winreg.OpenKey(winreg.HKEY_CURRENT_USER, sub_key_path)
            device_name = winreg.QueryValueEx(sub_key, "Label")[0]
            device_class = winreg.QueryValueEx(sub_key, "Class")[0]
            known_devices.append((device_name, device_class))
            i += 1
    except OSError:
        pass
    
    winreg.CloseKey(key)
    return known_devices
  1. 创建一个图形界面窗口并显示读取到的记录信息:
def show_known_devices():
    known_devices = read_known_devices()
    
    window = tk.Tk()
    window.title("Known Devices")
    
    for i, (device_name, device_class) in enumerate(known_devices, 1):
        label = tk.Label(window, text=f"{i}. {device_name} - {device_class}")
        label.pack()
    
    window.mainloop()
  1. 调用show_known_devices()函数来显示图形界面窗口:
show_known_devices()

这样,运行脚本后将会显示一个图形界面窗口,其中展示了读取到的记录信息

使用python37编写脚本读取SOFTWAREMicrosoftWindowsCurrentVersionExplorerAutoplayHandlersKnownDevices中详细的记录信息并用图形界面展示

原文地址: http://www.cveoy.top/t/topic/hYqk 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录