CPUの種類、クロック数などの各情報を取得する。
WMI(Windows Management Instrumentation)を利用してCPUの各情報を取得します。
VBAでWMIから情報を取得するにはSWbemLocatorオブジェクトのConnectServerメソッドを利用してコンピューター上の WMIへ接続することで取得できます。
CPUの情報は接続したWMIの Win32_Processorクラス から取得します。
サンプルコードでは下記の情報を取得するコードを掲載しています。
・CPUの種類、名前、製造元、現在のクロック周波数、最大クロック周波数
'*****************************************************************
' CPUの情報取得
'*****************************************************************
Sub getCPUInfo()
'SWbemLocatorオブジェクトを作成してWMIに接続
Dim oWMI As Object
Set oWMI = CreateObject("WbemScripting.SWbemLocator").ConnectServer
'オブジェクト取得のクエリを実行
Dim oQrySet As Object
Set oQrySet = oWMI.ExecQuery("Select * From Win32_Processor")
'CPU情報の取得
Dim oPrc As Object
For Each oPrc In oQrySet
Debug.Print "-------------------------------------------------------"
Debug.Print "(" & oPrc.DeviceID & ")"
Debug.Print "種類:" & oPrc.Description
Debug.Print "名前:" & oPrc.Name
Debug.Print "製造元:" & oPrc.Manufacturer
Debug.Print "現在のクロック周波数:" & CStr(oPrc.CurrentClockSpeed)
Debug.Print "最大クロック周波数:" & CStr(oPrc.MaxClockSpeed)
Next
Set oPrc = Nothing
Set oQrySet = Nothing
Set oWMI = Nothing
End Sub
■実行結果