Get System Information(cpu Speed-total Ram-graphic Card Model Etc.) Under Windows
Solution 1:
I've been wondering how to do this myself for a while now, so I dug around a bit and came up with this solution using wmi
(which requires pywin32
). Of course, it goes without saying, this only works on Windows machines (and the question has the Windows
tag).
import wmi
computer = wmi.WMI()
computer_info = computer.Win32_ComputerSystem()[0]
os_info = computer.Win32_OperatingSystem()[0]
proc_info = computer.Win32_Processor()[0]
gpu_info = computer.Win32_VideoController()[0]
os_name = os_info.Name.encode('utf-8').split(b'|')[0]
os_version = ' '.join([os_info.Version, os_info.BuildNumber])
system_ram = float(os_info.TotalVisibleMemorySize) / 1048576# KB to GBprint('OS Name: {0}'.format(os_name))
print('OS Version: {0}'.format(os_version))
print('CPU: {0}'.format(proc_info.Name))
print('RAM: {0} GB'.format(system_ram))
print('Graphics Card: {0}'.format(gpu_info.Name))
Output example:
OS Name:MicrosoftWindows7UltimateOS Version:6.1.76017601CPU:Intel(R)Core(TM)i7-4790CPU@3.60GHzRAM:15.9443855286GBGraphics Card:NVIDIAGeForceGTX960
You can install both required packages via pip
:
pip install --upgrade wmi
pip install --upgrade pypiwin32
To see what other variables you can access in various Win32 controller classes, take a look at this documentation:
Related answer found on SO: https://stackoverflow.com/a/11785020/295246
Update: For System RAM, you can use either os_info.TotalVisibleMemorySize
(returns the value in kilobytes) or computer_info.TotalPhysicalMemory
(returns the value in bytes). If you use the latter, you can use hurry.filesize
to quickly convert it to a pretty human readable string.
For example:
from hurry.filesize import size
...
size(int(computer_info.TotalPhysicalMemory))
Which in my case outputs: 15G
You can even modify the G to whatever else you want. See this SO answer for more info: https://stackoverflow.com/a/5194348/295246
Post a Comment for "Get System Information(cpu Speed-total Ram-graphic Card Model Etc.) Under Windows"