python wmi使用
python wmi
官方开发文档https://msdn.microsoft.com/en-us/library/aa394388(v=vs.85).aspx
WMI使用的WIN32_类库名 http://blog.csdn.net/liuxingbin/article/details/6790124
win32com下载地址:https://sourceforge.net/projects/pywin32/files/pywin32/
wmi下载地址:https://pypi.python.org/pypi/WMI/1.4.9
获取cpu用例
import wmi def get_cpu(self): # Initilization c = wmi.WMI() data_dict = {} for cpu in c.Win32_Processor(): device = cpu.DeviceID.lower() # Get cpu_usage data_dict[device] = {'volume': float(cpu.LoadPercentage), 'unit': '%'} return data_dict print get_cpu()
获取风扇信息
import wmi def get_fan(self): # Initilization c = wmi.WMI() # c.Win32_ActionCheck() for i in c.Win32_Fan(): print i print get_fan()