Python uses the wmi module to obtain the windows System Information Monitoring System

Source: Internet
Author: User
Tags disk usage
Python uses the WMI module to obtain the hardware information of the Windows system: hard disk partition, usage, memory size, CPU model, current running process, self-starting program and location, and system version. Python uses the WMI module to obtain the hardware information of the Windows system: hard disk partition, usage, memory size, CPU model, current running process, self-starting program and location, and system version.

This example describes how to use the wmi module in python to obtain the system information monitoring system in 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 () # obtain the OS version for sys in c. win_OperatingSystem (): print "Version: % s" % sys. caption. encode ("UTF"), "Vernum: % s" % sys. buildNumber print sys. OSArchitecture. encode ("UTF") # whether the system is a bit or a bit of print sys. numberOfProcesses # Total number of processes running on the current system def cpu_mem (): c = wmi. WMI () # CPU type and memory 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 () # obtain the hard disk partition 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 # obtain the disk usage percentage for disk in c. win_LogicalDisk (DriveType =): print disk. caption, "%. f % free "% (. * long (disk. freeSpace)/long (disk. size) def network (): c = wmi. WMI () # obtain the MAC address and IP address 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 ()

The above content is about how to use the wmi module in python to obtain the system information monitoring system in windows, and I hope to help you.

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.