安装vmi

https://pypi.org/project/WMI/#history

脚本如下:

  1. #!/usr/bin/env python
  2. #coding:utf-
  3.  
  4. import wmi
  5. import os
  6. import sys
  7. import platform
  8. import time
  9.  
  10. def sys_version():
  11. c = wmi.WMI ()
  12. #获取操作系统版本
  13. for sys in c.Win32_OperatingSystem():
  14. print "Version:%s" % sys.Caption.encode("UTF8"),"Vernum:%s" % sys.BuildNumber
  15. print sys.OSArchitecture.encode("UTF8")#系统是32位还是64位的
  16. print sys.NumberOfProcesses #当前系统运行的进程总数
  17.  
  18. def cpu_mem():
  19. c = wmi.WMI ()
  20. #CPU类型和内存
  21. for processor in c.Win32_Processor():
  22. #print "Processor ID: %s" % processor.DeviceID
  23. print "Process Name: %s" % processor.Name.strip()
  24. for Memory in c.Win32_PhysicalMemory():
  25. print "Memory Capacity: %.fMB" %(int(Memory.Capacity)/)
  26.  
  27. def cpu_use():
  28. #5s取一次CPU的使用率
  29. c = wmi.WMI()
  30. while True:
  31. for cpu in c.Win32_Processor():
  32. timestamp = time.strftime('%a, %d %b %Y %H:%M:%S', time.localtime())
  33. print '%s | Utilization: %s: %d %%' % (timestamp, cpu.DeviceID, cpu.LoadPercentage)
  34. time.sleep()
  35.  
  36. def disk():
  37. c = wmi.WMI ()
  38. #获取硬盘分区
  39. for physical_disk in c.Win32_DiskDrive ():
  40. for partition in physical_disk.associators ("Win32_DiskDriveToDiskPartition"):
  41. for logical_disk in partition.associators ("Win32_LogicalDiskToPartition"):
  42. print physical_disk.Caption.encode("UTF8"), partition.Caption.encode("UTF8"), logical_disk.Caption
  43.  
  44. #获取硬盘使用百分情况
  45. for disk in c.Win32_LogicalDisk (DriveType=):
  46. print disk.Caption, "%0.2f%% free" % (100.0 * long (disk.FreeSpace) / long (disk.Size))
  47.  
  48. def network():
  49. c = wmi.WMI ()
  50. #获取MAC和IP地址
  51. for interface in c.Win32_NetworkAdapterConfiguration (IPEnabled=):
  52. print "MAC: %s" % interface.MACAddress
  53. for ip_address in interface.IPAddress:
  54. print "ip_add: %s" % ip_address
  55. print
  56.  
  57. #获取自启动程序的位置
  58. for s in c.Win32_StartupCommand ():
  59. print "[%s] %s <%s>" % (s.Location.encode("UTF8"), s.Caption.encode("UTF8"), s.Command.encode("UTF8"))
  60.  
  61. #获取当前运行的进程
  62. for process in c.Win32_Process ():
  63. print process.ProcessId, process.Name
  64.  
  65. def main():
  66. sys_version()
  67. #cpu_mem()
  68. #disk()
  69. #network()
  70. #cpu_use()
  71.  
  72. if __name__ == '__main__':
  73. main()
  74. print platform.system()
  75. print platform.release()
  76. print platform.version()
  77. print platform.platform()
  78. print platform.machine()

执行结果:

  1. Version:Microsoft Windows 家庭中文版 Vernum:
  2.  
  3. Windows
  4.  
  5. 10.0.
  6. Windows--10.0.
  7. AMD64

参考:http://blog.51cto.com/wangwei007/1158075

Python用WMI模块获取windowns系统信息的更多相关文章

  1. python使用wmi模块获取windows下的系统信息监控系统-乾颐堂

    Python用WMI模块获取Windows系统的硬件信息:硬盘分区.使用情况,内存大小,CPU型号,当前运行的进程,自启动程序及位置,系统的版本等信息. 本文实例讲述了python使用wmi模块获取w ...

  2. Python使用WMI模块获取Windows系统的硬件信息,并使用pyinstaller库编译打包成exe的可执行文件

    由于公司现阶段大多数应用软件都是基于Windows系统开发和部署,很多软件安装部署都是在windows server 2012.windows server 2008之类的服务器上,部门同事每次测试一 ...

  3. python用WMI模块获取系统命名空间

    可以和winmgmts的查询页面对应 from win32com.client import GetObject import pywintypes result=[] def enum_namesp ...

  4. python封装configparser模块获取conf.ini值(优化版)

    昨天晚上封装了configparser模块,是根据keyname获取的value.python封装configparser模块获取conf.ini值 我原本是想通过config.ini文件中的sect ...

  5. python wmi模块 获取windows内部信息

    WMI (Windows Management Instrumentation) 模块可用于获取 Windows 内部信息,在使用Python获取Windows系统上的相关的信息可以使用WMI接口来获 ...

  6. python之psutil模块(获取系统性能数据)

    psutil模块 1.介绍 psutil是一个跨平台库(http://code.google.com/p/psutil/),能够轻松实现获取系统运行的进程和系统利用率(包括CPU.内存.磁盘.网络等) ...

  7. python通过getopt模块获取执行命令参数

    python脚本和shell脚本一样可以获取命令行的参数,根据不同的参数,执行不同的逻辑处理. 通常我们可以通过getopt模块获得不同的执行命令和参数. 下面我通过新建一个test.py的脚本解释下 ...

  8. python封装configparser模块获取conf.ini值

    configparser模块是python自带的从文件中获取固定格式参数的模块,因为是python只带的,大家用的应该很多,我觉得这个参数模块比较灵活,添加参数.修改参数.读取参数等都有对应的参数供用 ...

  9. python使用platform模块获取系统环境并去除换行符

    近来在porting一个网站,企图拿到这个网站的数据来做分析.为了支持多系统环境的正常运行.需要知道当前系统环境的是什么OS? 1.python内置platform库.可以很方便得到当前系统环境时什么 ...

随机推荐

  1. 从零开始のcocos2dx生活(八)ParticleSystemQuad

    https://learnopengl-cn.github.io/01%20Getting%20started/04%20Hello%20Triangle/#_1 写的真的非常好-最近没时间拜读,只看 ...

  2. CSRF绕过后端Referer校验

    CSRF绕过后端Referer校验分正常情况和不正常的情况,我们这里主要讨论开发在写校验referer程序时,不正常的情况下怎么进行绕过. 正常情况 正常的情况指服务器端校验Referer的代码没毛病 ...

  3. 小小知识点(三十九) 正交频分复用OFDM的基本原理及实现

    引言 符号间干扰(ISI)是无线传输系统设计中需要考虑的因素,采用什么样的处理方法取决于数据传输速率或等效传输带宽来决定 (1)若数据速率低且与信道最大延迟相比符号持续时间较长,那么就可能无需任何均衡 ...

  4. linux入门系列3--常见的linux远程登陆管理工具

    服务器一般是云服务器或者放置在机房,我们日常工作中通过远程连接工具连接到服务器进行操作,这类工具很多(如SecureCRT.XShell.Putty.FinallShell.TeamViewer以及w ...

  5. java数据结构之常用排序算法

    冒泡排序 private void maopao(int arr[]) { for (int i = 0; i < arr.length; i++) { for (int j = 0; j &l ...

  6. 《大厂面试》京东+百度一面,不小心都拿了Offer

    你知道的越多,你不知道的越多 点赞再看,养成习惯 本文 GitHub https://github.com/JavaFamily 已收录,有一线大厂面试点思维导图,也整理了很多我的文档,欢迎Star和 ...

  7. Java类成员之属性

    属性含义:对应类中的成员变量. 语法格式:修饰符 数据类型 属性名 = 初始化值; 1.修饰符常用的有权限修饰符(private.default.protected.public) 以及其他修饰符(s ...

  8. 从源码角度来看BeanFactory和ApplicationContext的关系

    大家好,我是小黑,这是年前的最后一篇推文,提前祝大家新年快乐~~ 这次我们从源码角度来聊聊BeanFactory和ApplicationContext的关系,讲一些网上文章不曾提到的点. 官方描述 先 ...

  9. python 矩阵向右旋转90°(分行输入输出)

    输入格式 第一行输入两个整数n,m,用空格隔开. 接下来n行,每行输入m个整数,表示输入矩阵.矩阵元素都是int范围内的整数. 输出格式 输出m行,每行n个空格隔开的整数,表示旋转以后的矩阵.注意:每 ...

  10. 【开源】后台权限管理系统升级到aspnetcore3.1

    *:first-child { margin-top: 0 !important; } .markdown-body>*:last-child { margin-bottom: 0 !impor ...