Python uses WMI module to get System Information monitoring system under Windows

Source: Internet
Author: User
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.

  • 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.