Python的功能模块[0] -> wmi -> 获取 Windows 内部信息
wmi模块 / wmi Module
WMI (Windows Management Instrumentation) 模块可用于获取 Windows 内部信息。该模块需要 win32com 的支持,环境安装如下,
pip install wmi
pip install pypiwin32
模块信息
WMI() 类
类实例化:w = wmi.WMI()
类的功能: 用于生成 WMI 的实例
传入参数: 无
返回参数: w
Win32_Processor() 方法
函数调用: processorList = w.Win32_Processor()
函数功能: 用于获取处理器信息对象,并存以列表形式
传入参数: 无
返回参数: processorList
processorList: list类型,list中每个元素均为一个含cpu信息的object
cpu object通过object.name调用,所含信息包括:
instance of Win32_Processor { AddressWidth = 64; Architecture = 9; Availability = 3; Caption = "Intel64 Family 6 Model 78 Stepping 3"; CpuStatus = 1; CreationClassName = "Win32_Processor"; CurrentClockSpeed = 2376; CurrentVoltage = 9; DataWidth = 64; Description = "Intel64 Family 6 Model 78 Stepping 3"; DeviceID = "CPU0"; ExtClock = 100; Family = 205; L2CacheSize = 512; L3CacheSize = 3072; L3CacheSpeed = 0; Level = 6; LoadPercentage = 29; Manufacturer = "GenuineIntel"; MaxClockSpeed = 2401; Name = "Intel(R) Core(TM) i5-6300U CPU @ 2.40GHz"; NumberOfCores = 2; NumberOfLogicalProcessors = 4; PowerManagementSupported = FALSE; ProcessorId = "BFEBFBFF000406E3"; ProcessorType = 3; Revision = 19971; Role = "CPU"; SocketDesignation = "U3E1"; Status = "OK"; StatusInfo = 3; SystemCreationClassName = "Win32_ComputerSystem"; SystemName = "CN00208511"; UpgradeMethod = 1; Version = ""; };
Win32_PhysicalMemory() 方法
函数调用: memModuleList = w.Win32_PhysicalMemory()
函数功能: 用于获取物理内存信息对象,并存以列表形式
传入参数: 无
返回参数: memModuleList
memModuleList: list 类型,list 中每个元素均为一个含物理内存信息的 object
物理内存 object 通过 object.name 调用,所含信息包括:
instance of Win32_PhysicalMemory { BankLabel = "ChannelA"; Capacity = "8589934592"; Caption = "Physical Memory"; CreationClassName = "Win32_PhysicalMemory"; DataWidth = 64; Description = "Physical Memory"; DeviceLocator = "Bottom-Slot 1(left)"; FormFactor = 12; InterleaveDataDepth = 0; InterleavePosition = 0; Manufacturer = "Hynix/Hyundai"; MemoryType = 0; Name = "Physical Memory"; PartNumber = "HMA81GS6AFR8N-UH "; PositionInRow = 1; SerialNumber = "28ECE200"; Speed = 2133; Tag = "Physical Memory 0"; TotalWidth = 64; TypeDetail = 16512; };