Python uses WMI modules to obtain hardware information about the Windows system: Partition of hard disk, usage, memory size, CPU model, current running process, self-launcher and location, system version, etc.
This article explains how Python uses the WMI module to get the System Information monitoring system under Windows
#!/usr/bin/env python #-*-coding:utf--*-#http://www.cnblogs.com/liu-ke/import WMI import OS import sys import Platform Import Time Def sys_version (): c = WMI. WMI () #获取操作系统版本 for SYS in C.win_operatingsystem (): print "version:%s"% sys. Caption.encode ("UTF"), "vernum:%s"% sys. BuildNumber Print sys. Osarchitecture.encode ("UTF") #系统是位还是位的 print sys. Numberofprocesses #当前系统运行的进程总数 def cpu_mem (): c = WMI. WMI () #CPU类型和内存 for processor in C.win_processor (): #print "Processor ID:%s"% processor. DeviceID print "Process Name:%s"% processor. Name.strip () for Memory in C.win_physicalmemory (): print "Memory capacity:%.FMB"% (int (memory.capacity)/) def di SK (): c = WMI. WMI () #获取硬盘分区 for Physical_disk in C.win_diskdrive (): For partition in Physical_disk.associators ("WIN_DISKD Rivetodiskpartition "): For Logical_disk in Partition.associators (" Win_logicaldisktopartition "): Print PHY Sical_disk. Caption.eNcode ("UTF"), partition. Caption.encode ("UTF"), Logical_disk. Caption #获取硬盘使用百分情况 for disk in C.win_logicaldisk (drivetype=): Print disk. Caption, "%.f%% free"% (. * Long (disk). FreeSpace)/long (disk. Size) def network (): c = WMI. WMI () #获取MAC和IP地址 for interface in C.win_networkadapterconfiguration (ipenabled=): print "MAC:%s"% INTERFAC E.macaddress for IP_Address in interface. Ipaddress:print "Ip_add:%s"% ip_address Print def main (): Sys_version () Cpu_mem () #disk () #network () if __name__ = = ' __main__ ': Main () print Platform.system () print platform.release () print platform.version ( ) print platform.platform () print platform.machine ()
This is about Python's knowledge of using the WMI module to get the System Information monitoring system under Windows, and we hope to help.