遍历系统中的所有逻辑设备:
1
   | for device in wmi.WMI().CIM_LogicalDevice():
   | 
 
这部分代码使用 wmi 模块遍历系统中的所有逻辑设备。
提取每个逻辑设备的信息:
1 2 3 4 5 6 7 8
   | item = {     "PNPDeviceID": device.PNPDeviceID if hasattr(device, "PNPDeviceID") else "",     "Description": device.Description if hasattr(device, "Description") else "",     "Caption": device.Caption if hasattr(device, "Caption") else "",     "Manufacturer": device.Manufacturer if hasattr(device, "Manufacturer") else "",     "PNPClass": device.PNPClass if hasattr(device, "PNPClass") else "",     "ClassGuid": device.ClassGuid if hasattr(device, "ClassGuid") else "", }
  | 
 
这部分代码将每个逻辑设备的信息提取出来,并存储在一个字典 item 中。如果某个属性不存在,它会将该属性的值设置为空字符串。
处理获取到的逻辑设备信息:
1 2 3
   | clean_data = get_line(self, item, self.display_list) data = json.dumps(clean_data, ensure_ascii=False) write_file(self.file, data)
   | 
 
这部分代码调用 get_line 方法处理 item,并将处理后的数据转换为 JSON 格式。然后,它将 JSON 数据写入到输出文件中。