例 1:
Python は WMI モジュールを使用して、Windows システムのハードウェア情報 (ハードディスク パーティション、使用状況、メモリ サイズ、CPU モデル、現在実行中のプロセス、自動起動プログラムと場所、システム バージョン、その他の情報) を取得します。
#!/usr/bin/env python
# -* - コーディング: utf-8 -*-
import wmi
import os
import sys
import platform
import time
def sys_version():
c = wmi.WMI ()
#c.Win32_OperatingSystem() の sys のオペレーティング システム バージョン
を取得します:
print "バージョン:%s" % sys.Caption.encode("UTF8") ,"Vernum: %s" % sys.BuildNumber
print sys.OSArchitecture.encode("UTF8")#システムは 32 ビットまたは 64 ビットです
print sys.NumberOfProcesses #実行中のプロセスの総数現在のシステム
def cpu_mem():
c = wmi.WMI ()
#CPU タイプとメモリ
c.Win32_Processor():
#print "プロセッサ ID: %s" %processor.DeviceID
print "プロセス名: %s" %processor.Name.strip()
c.Win32_PhysicalMemory() のメモリ:
print "メモリ容量: % .fMB" %(int(Memory.Capacity)/1048576)
def cpu_use():
#5 秒ごとに CPU 使用率を取得します
c = wmi.WMI()
while True:
c .Win32_Processor() の CPU:
timestamp = time.strftime('%a, %d %b %Y %H:%M:%S', time.localtime())
timestamp = time. %s: %d %%' % (timestamp, cpu.DeviceID, cpu.LoadPercentage)
time.sleep(5)
def disc():
c = wmi.WMI ()
#c.Win32_DiskDrive の物理ディスクのハード ディスク パーティション
を取得します ():
の物理ディスク.associators のパーティション ("Win32_DiskDriveToDiskPartition"):
のパーティション.associators の論理ディスク("Win32_LogicalDiskToPartition" ): PRINT Physical_disk.caption.encode ("UTF8")、partition.caption.encode ("UTF8")、logical_disk.caption
#🎜 🎜 🎜
DISK の場合C の場合。Win32_logicaldisk (DriveType=3):
print disc.Caption, "%0.2f%% free" % (100.0 * long (disk.FreeSpace) / long (disk.Size))
def network() :
c = wmi.WMI ()
#c.Win32_NetworkAdapterConfiguration のインターフェイスの MAC アドレスと IP アドレスを取得します
(IPEnabled=1):
print "MAC: %s" % Interface.MACAddress
for ip_address ininterface.IPAddress:
print "ip_add: %s" % ip_address
# s の自己起動プログラム
の場所を取得しますc.Win32_StartupCommand () 内:
print "[%s] %s " % (s.Location.encode("UTF8"), s.Caption.encode("UTF8"), s. Command.encode("UTF8" ))
#c.Win32_Process () のプロセスの現在実行中のプロセス
を取得します:
print process.ProcessId, process.Name
def main() :
sys_version()
#cpu_mem()
#disk()
#network()
#cpu_use()
if __name__ == '__main__':
main()
print platform.system()
print platform.release()
print platform.version()
print platform.platform()
print platform.machine()
例 2:
あまり使用しないので、CPU、メモリ、ハードディスクのみを取得します。その他のリソースが必要な場合は、msdn を参照してください。
import os
import win32api
import win32con
import wmi
import time
def getSysInfo(wmiService = None):
result = {}
if wmiService == None:
wmiService = wmi.WMI()
# cpu
wmiService の CPU 用。 Win32_Processor():
timestamp = time.strftime('%a, %d %b %Y %H:%M:%S', time.localtime())
result['cpuPercent'] = cpu .loadPercentage
# メモリ
cs = wmiService.Win32_ComputerSystem()
os = wmiService.Win32_OperatingSystem()
result['memTotal'] = int(int(cs[0].TotalPhysicalMemory)/1024 /1024)
result['memFree'] = int(int(os[0].FreePhysicalMemory)/1024)
#disk
result['diskTotal'] = 0
result['diskFree '] = 0
wmiService.Win32_LogicalDisk(DriveType=3) のディスク:
result['diskTotal'] += int(disk.Size)
result['diskFree'] += int(disk .FreeSpace)
result['diskTotal'] = int(result['diskTotal']/1024/1024)
result['diskFree'] = int(result['diskFree']/1024/1024)
結果を返す
if __name__ == '__main__':
wmiService = wmi.WMI()
while True:
print getSysInfo(wmiService)
time.sleep(3)
使用されている wmi モジュールは、wmi の初期化時にシステム リソースを大量に占有しているため、必要に応じて循環取得し、循環体の外側で wmi オブジェクトを初期化してから関数の領域に転送すると、CPU リソースが発生しません。

本篇文章给大家带来了关于Python的相关知识,其中主要介绍了关于Seaborn的相关问题,包括了数据可视化处理的散点图、折线图、条形图等等内容,下面一起来看一下,希望对大家有帮助。

本篇文章给大家带来了关于Python的相关知识,其中主要介绍了关于进程池与进程锁的相关问题,包括进程池的创建模块,进程池函数等等内容,下面一起来看一下,希望对大家有帮助。

本篇文章给大家带来了关于Python的相关知识,其中主要介绍了关于简历筛选的相关问题,包括了定义 ReadDoc 类用以读取 word 文件以及定义 search_word 函数用以筛选的相关内容,下面一起来看一下,希望对大家有帮助。

本篇文章给大家带来了关于Python的相关知识,其中主要介绍了关于数据类型之字符串、数字的相关问题,下面一起来看一下,希望对大家有帮助。

本篇文章给大家带来了关于Python的相关知识,其中主要介绍了关于numpy模块的相关问题,Numpy是Numerical Python extensions的缩写,字面意思是Python数值计算扩展,下面一起来看一下,希望对大家有帮助。

VS Code的确是一款非常热门、有强大用户基础的一款开发工具。本文给大家介绍一下10款高效、好用的插件,能够让原本单薄的VS Code如虎添翼,开发效率顿时提升到一个新的阶段。

pythn的中文意思是巨蟒、蟒蛇。1989年圣诞节期间,Guido van Rossum在家闲的没事干,为了跟朋友庆祝圣诞节,决定发明一种全新的脚本语言。他很喜欢一个肥皂剧叫Monty Python,所以便把这门语言叫做python。


ホットAIツール

Undresser.AI Undress
リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover
写真から衣服を削除するオンライン AI ツール。

Undress AI Tool
脱衣画像を無料で

Clothoff.io
AI衣類リムーバー

AI Hentai Generator
AIヘンタイを無料で生成します。

人気の記事

ホットツール

SublimeText3 英語版
推奨: Win バージョン、コードプロンプトをサポート!

SublimeText3 中国語版
中国語版、とても使いやすい

WebStorm Mac版
便利なJavaScript開発ツール

SublimeText3 Mac版
神レベルのコード編集ソフト(SublimeText3)

SublimeText3 Linux 新バージョン
SublimeText3 Linux 最新バージョン

ホットトピック



