python - 如何从 Win32_PnPEntity 实例中提取特定属性?

标签 python winapi wmi pywin32 wql

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)

此函数(查询)通常返回所有物理 PNP 设备,以下是输出示例:

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";
};

问题是,如果我只想提取实例的“PNPDeviceID”,如何在 python 中执行此操作,而不更改 WQL?

最佳答案

没关系,在 WMI python doc 中列出。 WQL 以列表形式返回答案,并且有一个工厂方法“__getattr__(self,'attribute_name'_)”使用特定属性名称返回数据。

关于python - 如何从 Win32_PnPEntity 实例中提取特定属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33911001/

相关文章:

python - 使用 pandas 数据框列中的值更改 DateTime 对象的日期

python - 用逆矩阵替换矩阵的所有元素

c++ - 如何在不使用文件句柄的情况下获取文件索引?

c# - 获取特定应用程序的屏幕截图

windows - 如何检查CD-ROM是真实的还是虚拟的

c# - 使用 TimeStamp_Sys100NS 的负 CPU 使用率

python - 在 Python 中评估数学表达式

python - 如何防止 python 服务器写入终端窗口?

c++ - SetTimer() 陷阱

c# - RPC 服务器不可用。 (HRESULT : 0x800706BA) when connecting to remote computer 的异常