How to extract a particular attribute from instance of Win32_PnPEntity?

拥有回忆 提交于 2019-12-24 12:34:39

问题


def getPnpDeviceInfo():
    c = wmi.WMI()
    wql = "SELECT * FROM Win32_PnPEntity WHERE Manufacturer != 'Microsoft' AND NOT PNPDeviceID LIKE 'ROOT\\%'"
    print ("All physical PNP devices")
    for J in c.query(wql):
    print(J)

This function (the query) typically returns all physical PNP devices, here is an output sample :

instance of Win32_PnPEntity
{
Caption = "ACPI Lid";
ClassGuid = "{4d36e97d-e325-11ce-bfc1-08002be10318}";
ConfigManagerErrorCode = 0;
ConfigManagerUserConfig = FALSE;
CreationClassName = "Win32_PnPEntity";
Description = "ACPI Lid";
DeviceID = "ACPI\\PNP0C0D\\2&DABA3FF&3";
HardwareID = {"ACPI\\PNP0C0D", "*PNP0C0D"};
Manufacturer = "(Standard system devices)";
Name = "ACPI Lid";
PNPDeviceID = "ACPI\\PNP0C0D\\2&DABA3FF&3";
Status = "OK";
SystemCreationClassName = "Win32_ComputerSystem";
SystemName = "SUSDUTTA-LAP";
};

Question is, if I want to extract just the "PNPDeviceID" of the instance, how to do so in python, without changing the WQL?


回答1:


Never mind, figured in the WMI python doc. The WQL returns the answer as a list, and there is a factory method "__getattr__(self,'attribute_name'_)" which returned the data using specific attribute name.



来源:https://stackoverflow.com/questions/33911001/how-to-extract-a-particular-attribute-from-instance-of-win32-pnpentity

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!