Python的用WMI模塊獲取的Windows系統的硬件信息:硬盤分區,使用狀況,內存大小,CPU型號,當前運行的進程,自啓動程序及位置,系統的版本等信息。python
本文實例講述了python使用wmi模塊獲取windows下的系統信息監控系統windows
#!/usr/bin/env python # -*- coding: utf-8 -*- 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 disk(): c = wmi.WMI () #獲取硬盤分區 for physical_disk in c.Win_DiskDrive (): for partition in physical_disk.associators ("Win_DiskDriveToDiskPartition"): for logical_disk in partition.associators ("Win_LogicalDiskToPartition"): print physical_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" % interface.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() Python資源分享秋秋裙855你們408努力893,內有安裝包,學習視頻資料,免費直播實戰案例。這裏是Python學習者的彙集地,零基礎,進階,都歡迎
以上內容是關於python使用wmi模塊獲取windows下的系統信息監控系統的相關知識,但願對你們有所幫助。學習