Python uses the wmi module to obtain the system information monitoring system in windows.
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.