wmi模块 / wmi Module


WMI (Windows Management Instrumentation) 模块可用于获取 Windows 内部信息。该模块需要 win32com 的支持,环境安装如下,

pip install wmi
pip install pypiwin32

模块信息


WMI()

类实例化:w = wmi.WMI()

类的功能: 用于生成 WMI 的实例

传入参数:

返回参数: w

Win32_Processor() 方法

函数调用: processorList = w.Win32_Processor()

函数功能: 用于获取处理器信息对象,并存以列表形式

传入参数:

返回参数: processorList

processorList: list类型,list中每个元素均为一个含cpu信息的object

cpu object通过object.name调用,所含信息包括:

instance of Win32_Processor
{
AddressWidth = 64;
Architecture = 9;
Availability = 3;
Caption = "Intel64 Family 6 Model 78 Stepping 3";
CpuStatus = 1;
CreationClassName = "Win32_Processor";
CurrentClockSpeed = 2376;
CurrentVoltage = 9;
DataWidth = 64;
Description = "Intel64 Family 6 Model 78 Stepping 3";
DeviceID = "CPU0";
ExtClock = 100;
Family = 205;
L2CacheSize = 512;
L3CacheSize = 3072;
L3CacheSpeed = 0;
Level = 6;
LoadPercentage = 29;
Manufacturer = "GenuineIntel";
MaxClockSpeed = 2401;
Name = "Intel(R) Core(TM) i5-6300U CPU @ 2.40GHz";
NumberOfCores = 2;
NumberOfLogicalProcessors = 4;
PowerManagementSupported = FALSE;
ProcessorId = "BFEBFBFF000406E3";
ProcessorType = 3;
Revision = 19971;
Role = "CPU";
SocketDesignation = "U3E1";
Status = "OK";
StatusInfo = 3;
SystemCreationClassName = "Win32_ComputerSystem";
SystemName = "CN00208511";
UpgradeMethod = 1;
Version = "";
};

Win32_PhysicalMemory() 方法

函数调用: memModuleList = w.Win32_PhysicalMemory()

函数功能: 用于获取物理内存信息对象,并存以列表形式

传入参数:

返回参数: memModuleList

memModuleList: list 类型,list 中每个元素均为一个含物理内存信息的 object

物理内存 object 通过 object.name 调用,所含信息包括:

instance of Win32_PhysicalMemory
{
BankLabel = "ChannelA";
Capacity = "";
Caption = "Physical Memory";
CreationClassName = "Win32_PhysicalMemory";
DataWidth = 64;
Description = "Physical Memory";
DeviceLocator = "Bottom-Slot 1(left)";
FormFactor = 12;
InterleaveDataDepth = 0;
InterleavePosition = 0;
Manufacturer = "Hynix/Hyundai";
MemoryType = 0;
Name = "Physical Memory";
PartNumber = "HMA81GS6AFR8N-UH ";
PositionInRow = 1;
SerialNumber = "28ECE200";
Speed = 2133;
Tag = "Physical Memory 0";
TotalWidth = 64;
TypeDetail = 16512;
};

Win32_LogicalDisk () 方法

函数调用: diskList = w.Win32_LogicalDisk(DriverType=3)

函数功能:用于获取磁盘信息对象,并存以列表形式

传入参数: *argv

DriverType: int 类型,筛选驱动类型

返回参数: diskList

diskList: list类型,list 中每个元素均为一个含磁盘信息的object

磁盘信息 object 通过object.name调用,所含信息包括:

instance of Win32_LogicalDisk
{
Access = 0;
Caption = "C:";
Compressed = FALSE;
CreationClassName = "Win32_LogicalDisk";
Description = "Local Fixed Disk";
DeviceID = "C:";
DriveType = 3;
FileSystem = "NTFS";
FreeSpace = "";
MaximumComponentLength = 255;
MediaType = 12;
Name = "C:";
Size = "";
SupportsDiskQuotas = FALSE;
SupportsFileBasedCompression = TRUE;
SystemCreationClassName = "Win32_ComputerSystem";
SystemName = "CN00208511";
VolumeName = "OSDisk";
VolumeSerialNumber = "3AFBC150";
}; instance of Win32_LogicalDisk
{
Access = 0;
Caption = "D:";
Compressed = FALSE;
CreationClassName = "Win32_LogicalDisk";
Description = "Local Fixed Disk";
DeviceID = "D:";
DriveType = 3;
FileSystem = "FAT32";
FreeSpace = "";
MaximumComponentLength = 255;
MediaType = 12;
Name = "D:";
Size = "";
SupportsDiskQuotas = FALSE;
SupportsFileBasedCompression = FALSE;
SystemCreationClassName = "Win32_ComputerSystem";
SystemName = "CN00208511";
VolumeName = "HP_TOOLS";
VolumeSerialNumber = "B2FBEEA0";
}; instance of Win32_LogicalDisk
{
Access = 0;
Caption = "E:";
Compressed = FALSE;
CreationClassName = "Win32_LogicalDisk";
Description = "Local Fixed Disk";
DeviceID = "E:";
DriveType = 3;
FileSystem = "NTFS";
FreeSpace = "";
MaximumComponentLength = 255;
MediaType = 12;
Name = "E:";
Size = "";
SupportsDiskQuotas = FALSE;
SupportsFileBasedCompression = TRUE;
SystemCreationClassName = "Win32_ComputerSystem";
SystemName = "CN00208511";
VolumeName = "HP_RECOVERY";
VolumeSerialNumber = "BCFC555B";
};

Win32_ NetworkAdapterConfiguration()方法

函数调用: interfaceList = w.Win32_NetworkAdapterConfiguration(IPEnabled=1)

函数功能: 用于网络接口信息对象,并存以列表形式

传入参数: *argv

IPEnabled: bool 类型,可传入1,默认为False,为 True 将显示 IP 信息

返回参数: interfaceList

interfaceList: list 类型,list 中每个元素均为一个网络接口信息的 object

网络接口信息 object 通过 object.name 调用,所含信息包括(部分具体信息已删除):

instance of Win32_NetworkAdapterConfiguration
{
Caption = "[00000011] Intel(R) Dual Band Wireless-AC 8260";
DatabasePath = "%SystemRoot%\\System32\\drivers\\etc";
DefaultIPGateway = {"192.168.1.1"};
Description = "Intel(R) Dual Band Wireless-AC 8260";
DHCPEnabled = TRUE;
DHCPLeaseExpires = "20170531002222.000000+480";
DHCPLeaseObtained = "20170530222222.000000+480";
DHCPServer = "192.168.1.1";
DNSDomain = "DHCP HOST";
DNSDomainSuffixSearchOrder = {"ericsson.se", "DHCP HOST"};
DNSEnabledForWINSResolution = FALSE;
DNSHostName = "";
DNSServerSearchOrder = {"", ""};
DomainDNSRegistrationEnabled = FALSE;
FullDNSRegistrationEnabled = TRUE;
GatewayCostMetric = {0};
Index = 11;
InterfaceIndex = 12;
IPAddress = {"", ""};
IPConnectionMetric = 20;
IPEnabled = TRUE;
IPFilterSecurityEnabled = FALSE;
IPSecPermitIPProtocols = {};
IPSecPermitTCPPorts = {};
IPSecPermitUDPPorts = {};
IPSubnet = {"", ""};
MACAddress = "";
ServiceName = "NETwNs64";
SettingID = "{}";
TcpipNetbiosOptions = 0;
WINSEnableLMHostsLookup = TRUE;
WINSScopeID = "";
};

利用wmi模块获取PC信息


获取PC信息的步骤主要有:

(1)打开存储信息的文件;

(2)实例化WMI类,利用各函数获取硬件信息类的列表;

(3)遍历硬件信息类列表,获取硬件信息并写入存储文件。

 import wmi
hardware=open('Hardware.txt', 'w') w=wmi.WMI() hardware.write("cpu type,main frequency:\n")
for processor in w.Win32_Processor():
hardware.write("Processor ID: %s" % processor.DeviceID)
hardware.write("\nProcess Name: %s" % processor.Name.strip()+'\n\n')
hardware.write('Memory size:')
totalMemSize=0
for memModule in w.Win32_PhysicalMemory():
totalMemSize+=int(memModule.Capacity)
hardware.write("\nMemory Capacity: %.2fMB" %((totalMemSize+1048575)/1048576)+'\n\n')
hardware.write('Hard disk usage:')
for disk in w.Win32_LogicalDisk (DriveType=3):
temp=disk.Caption+" %0.2f%% free" %(100.0 * int(disk.FreeSpace) / int(disk.Size))
hardware.write('\n'+temp)
hardware.write('\n')
hardware.write('\nIP and MAC:\n')
for interface in w.Win32_NetworkAdapterConfiguration(IPEnabled=1):
hardware.write('Network card driver information:')
hardware.write(interface.Description+'\n')
hardware.write('Network card MAC address:')
hardware.write(interface.MACAddress+'\n')
hardware.write('IP address:')
hardware.write(interface.IPAddress[0]+'\n')
hardware.write('Network IP interface')
hardware.write(interface.IPAddress[1]+'\n')
hardware.close()

最终可以在当前目录下得到一个包含硬件信息的文本文件。

Python的功能模块[0] -> wmi -> 获取 Windows 内部信息的更多相关文章

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

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

  2. Python使用wmi获取Windows相关信息

    在使用Python获取Windows系统上的相关的信息可以使用WMI接口来获取, 什么是wmi? WMI是一项核心的Windows管理技术,WMI作为一种规范和基础结构,通过它可以访问.配置.管理和监 ...

  3. Python WMI获取Windows系统信息 监控系统

    #!/usr/bin/env python # -*- coding: utf-8 -*- #http://www.cnblogs.com/liu-ke/ import wmi import os i ...

  4. 用PYTHON + PYWIN32 + WMI获取WINDOWS系统基本信息

    网上原码,去了DECODE编码的问题. PyScripter这个PYTHON的IDE工具在WIN下表现不错哟. 感觉比SPYDER,ERIC,SUBLEME TEXT3之类的好用呀.. #!/usr/ ...

  5. 利用python 与 wmi 获取WINDOWS基本信息

    #!/usr/bin/env python3.5 # -*- coding:utf8 -*- import platform import subprocess import wmi def serv ...

  6. Python WMI获取Windows系统信息

    #!/usr/bin/env python # -*- coding: utf-8 -*- #http://www.cnblogs.com/liu-ke/ import wmi import os i ...

  7. Python的功能模块[1] -> struct -> struct 在网络编程中的使用

    struct模块 / struct Module 在网络编程中,利用 socket 进行通信时,常常会用到 struct 模块,在网络通信中,大多数传递的数据以二进制流(binary data)存在. ...

  8. Python Django 功能模块

    Python Django模块 Django模块,是针对有django基础,对django功能进行模块化,方便下次使用. 一.注册模块 该注册采用邮箱验证,注册成功后会发送激活链接到邮箱. 邮箱验证参 ...

  9. Python的功能模块[4] -> pdb/ipdb -> 实现 Python 的单步调试

    pdb / ipdb 模块 / pdb / ipdb Module pdb 和 ipdb 的主要作用是用于 Python 程序的单步调试,Python 的调试可参考链接. 下面是一个简单的使用示例 i ...

随机推荐

  1. 剑指Offer - 九度1524 - 复杂链表的复制

    剑指Offer - 九度1524 - 复杂链表的复制2014-02-07 01:30 题目描述: 输入一个复杂链表(每个节点中有节点值,以及两个指针,一个指向下一个节点,另一个特殊指针指向任意一个节点 ...

  2. CodeIgniter学习笔记三:扩展CI的控制器、模型

    一.扩展CI中的控制器 有时需要对CI中的控制器作统一操作,如进行登录和权限验证,这时就可以通过扩展CI控制器来实现. 扩展CI控制器只需要在application/core文件夹中建一个继承自CI_ ...

  3. eclipse importing maven projects 卡顿

    导入一个maven工程后 一直显示 importing maven projects 9% 解决办法: 找到eclipse安装目录下的eclipse.ini 在最后加入 -vm $JAVA_HOME% ...

  4. HA集群基本概念详解

    一.高可用集群的定义 二.高可用集群的衡量标准 三.高可用集群的层次结构 四.高可用集群的分类 五.高可用集群常用软件 六.共享存储 七.集群文件系统与集群LVM 八.高可用集群的工作原理 一.高可用 ...

  5. hp raid配置

    http://www.cnblogs.com/zhangxinglong/p/5585139.html [root@192e168e100e27 ~]# fdisk -l Disk /dev/nvme ...

  6. VC调试篇:减少运行时错误,中断所有异常

    问题简述 我在Win7下写的MFC程序,想让它在winXP下运行.一般情况下,如果所有的依赖库都可以在XP下运行的话,那么在XP下运行时没问题的.但是,结果却... 本来程序在win7下运行得好好的, ...

  7. 九 DIP 依赖倒置原则

    首先看定义: 1.高层模块不依赖于低层模块,两者都应该依赖于抽象层 2.抽象不能依赖于细节,细节必须依赖于抽象 首先,模块是个抽象的概念,可以大到一个系统中的子系统作为一个模块,也可以是某个子系统中的 ...

  8. BETA(1)

    目录 组员情况 组员1(组长):胡绪佩 组员3:庄卉 组员4:家灿 组员5:凯琳 组员6:翟丹丹 组员7:何家伟 组员8:政演 组员9:黄鸿杰 组员10:刘一好 组员11:何宇恒 展示组内最新成果 团 ...

  9. Dubbo基础介绍

    基础知识 Dubbo是什么:Dubbo是一个分布式的服务框架,提供高性能和透明化的RPC远程调用方案,以及SOA服务治理方案 Dubbo涉及的知识: 远程调用:RMI.hassion.webservi ...

  10. CF 1103B Game with modulo

    题目 $a, x$ 是正整数.显然有 \begin{aligned} x \ge 2x \pmod{a} \implies a \le 2x \end{aligned} 若 $x \le a$ 则 \ ...