Python obtains windowns System information with WMI module

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.