プロセッサの情報取得 <TOP>
GetSystemInfoでプロセッサの情報を取得、レジストリからCPUのスピードを取得します。
GetSystemInfo システム情報を取得
RegOpenKey 指定されたレジストリキーをオープン
RegQueryValueEx レジストリの値を取得
RegCloseKey レジストリのハンドルを解放
左:HP(WindowsXP) 右:Dell(WindowsXP)
左:Valuestar(WindowsXP) 右:Hitachi(Windows2000)
'================================================================ '= プロセッサの情報取得
'= (GetProcessor.bas) '================================================================ #include "Windows.bi" #define PROCESSOR_ALPHA_21064 21064 ' #define PROCESSOR_ARCHITECTURE_ALPHA 2 ' #define PROCESSOR_ARCHITECTURE_ALPHA64 7' #define PROCESSOR_ARCHITECTURE_ARM 5 ' #define PROCESSOR_ARCHITECTURE_IA64 6 ' #define PROCESSOR_ARCHITECTURE_INTEL 0 ' #define PROCESSOR_ARCHITECTURE_MIPS 1 ' #define PROCESSOR_ARCHITECTURE_PPC 3 ' #define PROCESSOR_ARCHITECTURE_SHX 4 ' #define PROCESSOR_ARCHITECTURE_UNKNOWN &HFFFF ' #define PROCESSOR_ARM_7TDMI 70001 'WindowsCE #define PROCESSOR_ARM720 1824 'WindowsCE-0x720 #define PROCESSOR_ARM820 2080 'WindowsCE-0x820 #define PROCESSOR_ARM920 2336 'WindowsCE-0x920 #define PROCESSOR_HITACHI_SH3 10003 'WindowsCE #define PROCESSOR_HITACHI_SH3E 10004 'WindowsCE #define PROCESSOR_HITACHI_SH4 10005 'WindowsCE #define PROCESSOR_INTEL_386 386 ' #define PROCESSOR_INTEL_486 486 ' #define PROCESSOR_INTEL_PENTIUM 586 ' #define PROCESSOR_LEVEL_80386 3 ' #define PROCESSOR_LEVEL_80486 4 ' #define PROCESSOR_LEVEL_PENTIUM 5 ' #define PROCESSOR_LEVEL_PENTIUMII 6 ' #define PROCESSOR_MIPS_R4000 4000 ' #define PROCESSOR_MOTOROLA_821 821 'WindowsCE #define PROCESSOR_PPC_601 601 ' #define PROCESSOR_PPC_603 603 ' #define PROCESSOR_PPC_604 604 ' #define PROCESSOR_PPC_620 620 ' #define PROCESSOR_SHx_SH3 103 'WindowsCE #define PROCESSOR_SHx_SH4 104 'WindowsCE #define PROCESSOR_STRONGARM 2577 'WindowsCE-0xA11 #define sCPURegKey "HARDWARE\DESCRIPTION\System\CentralProcessor\0" #define HKEY_LOCAL_MACHINE -2147483646 'PCを利用するユーザーに共通の設定情報 Type SYSTEM_INFO dwOemID As Long dwPageSize As Long lpMinimumApplicationAddress As Long lpMaximumApplicationAddress As Long dwActiveProcessorMask As Long dwNumberOfProcessors As Long dwProcessorType As Long dwAllocationGranularity As Long wProcessorLevel As Integer wProcessorRevision As Integer End Type ' システム情報を取得 Declare Sub Api_GetSystemInfo Lib "Kernel32" Alias "GetSystemInfo" (lpSystemInfo As SYSTEM_INFO) ' 指定されたレジストリキーをオープン Declare Function Api_RegOpenKey& Lib "advapi32" Alias "RegOpenKeyA" (ByVal hKey&, ByVal lpSubKey$, phkResult&) ' レジストリの値を取得 Declare Function Api_RegQueryValueEx& Lib "advapi32" Alias "RegQueryValueExA" (ByVal hKey&, ByVal lpvName$, ByVal lpReserved&, ByVal lpType&, lpData As Any, lpcbData&) ' レジストリのハンドルを解放 Declare Function Api_RegCloseKey& Lib "advapi32" Alias "RegCloseKey" (ByVal hKey&) Var Shared List1 As Object Var Shared Button1 As Object List1.Attach GetDlgItem("List1") : List1.SetFontSize 12 Button1.Attach GetDlgItem("Button1") : Button1.SetFontSize 14 '================================================================ '= '================================================================ Declare Function GetCPUSpeed() As Long Function GetCPUSpeed() As Long Var hKey As Long Var cpuSpeed As Long Var Ret As Long 'CPU key オープン Ret = Api_RegOpenKey(HKEY_LOCAL_MACHINE, sCPURegKey, hKey) '値を取得 Ret = Api_RegQueryValueEx(hKey, "~MHz", 0, 0, cpuSpeed, 4) Ret = Api_RegCloseKey(hKey) GetCPUSpeed = cpuSpeed End Function '================================================================ '= '================================================================ Declare Function HiByte(ByVal wParam As Integer) As Byte Function HiByte(ByVal wParam As Integer) As Byte HiByte = (wParam And &HFF00) \ (&H100) End Function '================================================================ '= '================================================================ Declare Function LoByte(ByVal wParam As Integer) As Byte Function LoByte(ByVal wParam As Integer) As Byte LoByte = wParam And &HFF End Function '================================================================ '= '================================================================ Declare Sub Button1_on edecl () Sub Button1_on() Var si As SYSTEM_INFO Var tmp As String Var Ret As Long Api_GetSystemInfo si List1.ResetContent List1.AddString "NumberOfProcessors :" & Str$(si.dwNumberOfProcessors) Select Case si.dwProcessorType Case PROCESSOR_INTEL_386 tmp = " 386" Case PROCESSOR_INTEL_486 tmp = " 486" Case PROCESSOR_INTEL_PENTIUM tmp = " Pentium" Case PROCESSOR_MIPS_R4000 tmp = " MIPS 4000" Case PROCESSOR_ALPHA_21064 tmp = " Alpha" End Select List1.AddString "Processor Type :" & Str$(si.dwProcessorType) & tmp Select Case SI.wProcessorLevel Case PROCESSOR_LEVEL_80386 tmp = " Intel 80386" Case PROCESSOR_LEVEL_80486 tmp = " Intel 80486" Case PROCESSOR_LEVEL_PENTIUM tmp = " Intel Pentium" Case PROCESSOR_LEVEL_PENTIUMII tmp = " Intel Pentium Pro,U,V Or 4" End Select List1.AddString "Processor Level :" & Str$(si.wProcessorLevel) & tmp List1.AddString "Processor Revision :" & Str$(si.wProcessorRevision) & " Model" & Str$(HiByte(si.wProcessorRevision)) & ",Stepping" & Str$(LoByte(si.wProcessorRevision)) List1.AddString "CPU Speed :" & Str$(GetCPUSpeed()) & " MHz" End Sub '================================================================ '= '================================================================ While 1 WaitEvent Wend Stop End