Installing VMI
https://pypi.org/project/WMI/#history
The script is as follows:
#!/usr/bin/Env Python#coding:utf-8import wmiimport osimport sysimport platformimport timedef sys_version (): C=WMI. WMI () #获取操作系统版本 forSysinchC.win32_operatingsystem (): Print"version:%s"% sys. Caption.encode ("UTF8"),"vernum:%s"%sys. BuildNumber Print sys. Osarchitecture.encode ("UTF8") #系统是32位还是64位的 Print sys. Numberofprocesses #当前系统运行的进程总数def Cpu_mem (): C=WMI. WMI () #CPU类型和内存 forProcessorinchc.win32_processor (): #print"Processor ID:%s"%processor. DeviceID Print"Process Name:%s"%processor. Name.strip () forMemoryinchc.win32_physicalmemory (): Print"Memory Capacity:%.FMB"%(int(memory.capacity)/1048576) def cpu_use (): #5s取一次CPU的使用率 c=WMI. WMI () whileTrue: forCpuinchc.win32_processor (): Timestamp= Time.strftime ('%a,%d%b%Y%h:%m:%s', Time.localtime ()) Print'%s | Utilization:%s:%d percent'%(timestamp, CPU.) DeviceID, CPU. Loadpercentage) Time.sleep (5) def disk (): C=WMI. WMI () #获取硬盘分区 forPhysical_diskinchc.win32_diskdrive (): forPartitioninchPhysical_disk.associators ("win32_diskdrivetodiskpartition"): forLogical_diskinchPartition.associators ("win32_logicaldisktopartition"): Print Physical_disk. Caption.encode ("UTF8"), partition. Caption.encode ("UTF8"), Logical_disk. Caption #获取硬盘使用百分情况 forDiskinchC.win32_logicaldisk (drivetype=3): Print disk. Caption,"%0.2f%% Free"% (100.0*Long(Disk. FreeSpace)/Long(disk. Size)) def network (): C=WMI. WMI () #获取MAC和IP地址 for Interface inchC.win32_networkadapterconfiguration (ipenabled=1): Print"MAC:%s"%Interface. MACAddress forIP_Addressinch Interface. Ipaddress:print"Ip_add:%s"%ip_address Print #获取自启动程序的位置 forSinchC.win32_startupcommand (): Print"[%s]%s <%s>"% (S.location.encode ("UTF8"), S.caption.encode ("UTF8"), S.command.encode ("UTF8")) #获取当前运行的进程 forProcessinchc.win32_process (): Print Process. ProcessId, process. Namedef Main (): Sys_version () #cpu_mem () #disk () #network () #cpu_use ()if__name__ = ='__main__': Main () print Platform.system () print platform.release () print platform.version () print PLATFORM.PLATF ORM () print platform.machine ()
Execution Result:
Family Chinese version vernum:15063 155Windows10.0 . 15063 Windows-10.0. 15063 AMD64
Reference: http://blog.51cto.com/wangwei007/1158075
Python obtains windowns System information with WMI module