Skip to content

Instantly share code, notes, and snippets.

@takehiko
Created September 22, 2012 10:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save takehiko/3765789 to your computer and use it in GitHub Desktop.
Save takehiko/3765789 to your computer and use it in GitHub Desktop.
Get processor name, number of processors and clock speed using Win32OLE
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
# cpuinfo.rb : get processor name, number of processors and clock speed
# using Win32OLE
require "win32ole"
wmi = WIN32OLE.connect("winmgmts://")
query = wmi.ExecQuery("select * from Win32_Processor")
cpuinfo = nil
query.each {|obj| cpuinfo = obj; break}
name = cpuinfo.name
name_str = name.gsub(/\s{2,}/, " ")
core = cpuinfo.NumberOfLogicalProcessors
core_str = core > 1 ? " x #{core}" : ""
clock = cpuinfo.CurrentClockSpeed
clock_str = " (#{clock}MHz)"
puts [name_str, core_str, clock_str].join
# http://www.tech-notes.dyndns.org/wmi/
# http://www.wmifun.net/library/win32_processor.html
# http://q.hatena.ne.jp/1269364904
# grep model.name /proc/cpuinfo | sed -e 's/.*: //' | uniq -c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment