Récupérer le nom du processeur
Permet de récupérer le nom du processeur. (Par exemple : « Intel(R) Core(TM)2 Duo CPU T8100 @ 2.10GHz »)
- Systèmes :
- Windows
- Linux
- MacOs
- PureBasic 4.30
;@windows ;@author Progi1984 ;@linux ;@author Progi1984 ;@@macos ;@author jack ;@link http://www.purebasic.fr/english/viewtopic.php?p=282943#282943 ProcedureDLL.s System_GetCPUInfo() CompilerSelect #PB_Compiler_OS CompilerCase #PB_OS_Linux ;{ Protected lProgram.l Protected sOutput.s lProgram = RunProgram("grep", Chr(34)+"model name"+Chr(34)+" /proc/cpuinfo", "", #PB_Program_Open|#PB_Program_Read) If lProgram sOutput = ReadProgramString(lProgram) sOutput = ReplaceString(sOutput, "model name", "") sOutput = ReplaceString(sOutput, ":", "") sOutput = Trim(sOutput) ProcedureReturn sOutput Else ProcedureReturn "" EndIf ;} CompilerCase #PB_OS_MacOS ;{ ImportC "/usr/lib/libc.dylib" sysctlbyname.l(s.s,*buffer,*length,*null,*null2) EndImport Protected *MemBuffer Protected lMemLength.l = 128 *MemBuffer = AllocateMemory(lMemLength) sysctlbyname("machdep.cpu.brand_string", *MemBuffer, @lMemLength, 0, 0) ProcedureReturn PeekS(*MemBuffer) ;} CompilerCase #PB_OS_Windows ;{ Protected sSubKey.s, sKeyValue.s, sResult.s Protected lKey.l, lResultLen.l sSubKey = "HARDWARE\DESCRIPTION\System\CentralProcessor\0" sKeyValue = "ProcessorNameString" sResult = Space(255) lResultLen = 255 If RegOpenKeyEx_(#HKEY_LOCAL_MACHINE, sSubKey, #Null, #KEY_ALL_ACCESS, @lKey) = #ERROR_SUCCESS If lKey If RegQueryValueEx_(lKey, sKeyValue, 0, 0, @sResult, @lResultLen) = #ERROR_SUCCESS ProcedureReturn sResult EndIf RegCloseKey_(lKey) EndIf EndIf ;} CompilerEndSelect EndProcedure Debug System_GetCPUInfo()
Ajouter un commentaire