CPU Detection Code
I recently wrote the following CPU detection code:
; ---------------------------------------
; Installer Attributes
; ---------------------------------------
Caption "CPU Info"
OutFile "cpuinfo.exe"
!include StrFunc.nsh
${StrTok}
${StrLoc}
${StrCase}
; ---------------------------------------
; CPU Detection Code
; ---------------------------------------
Var CPU_TYPE
!macro CheckCPUExt list ext label_found
${StrLoc} $0 "${list}" " ${ext} " ">"
StrCmp $0 "" 0 ${label_found}
!macroend
Function DetectCPUType
Banner::show /NOUNLOAD "Detetcing your CPU Type, please be patient..."
StrCpy $CPU_TYPE 5 #RTM
File /oname=$PLUGINSDIR\cpuinfo.exe "installer\cpuinfo.exe"
nsExec::ExecToStack '"$PLUGINSDIR\cpuinfo.exe"'
Pop $0
Pop $1
Delete "$PLUGINSDIR\cpuinfo.exe"
StrCmp $0 "error" CPU_DETECTION_DONE
${StrTok} $1 "$1" "$\n$\r$\t:" "9" "1"
${StrCase} $1 "$1" "U"
; ------------------------------
StrCpy $0 "0"
StrCpy $2 " "
CPU_LOOP:
${StrTok} $3 $1 " " "$0" "1"
IntOp $0 $0 + 1
StrCmp $3 "" CPU_LOOP_END
StrCmp $3 "MMX" CPU_LOOP_FOUND
StrCmp $3 "3DNOW" CPU_LOOP_FOUND
StrCmp $3 "3DNOW2" CPU_LOOP_FOUND
StrCmp $3 "SSE" CPU_LOOP_FOUND
StrCmp $3 "SSE2" CPU_LOOP_FOUND
StrCmp $3 "SSE3" CPU_LOOP_FOUND
StrCmp $3 "SSSE3" CPU_LOOP_FOUND
Goto CPU_LOOP
CPU_LOOP_FOUND:
StrCpy $2 "$2$3 "
Goto CPU_LOOP
CPU_LOOP_END:
; ------------------------------
!insertmacro CheckCPUExt "$2" "MMX" HAS_MMX
Goto CPU_DETECTION_DONE
HAS_MMX:
!insertmacro CheckCPUExt "$2" "SSE" HAS_SSE
!insertmacro CheckCPUExt "$2" "3DNOW" HAS_3DNOW
Goto CPU_DETECTION_DONE
HAS_3DNOW:
StrCpy $CPU_TYPE 2 #Athlon
Goto CPU_DETECTION_DONE
HAS_SSE:
StrCpy $CPU_TYPE 3 #P3
!insertmacro CheckCPUExt "$2" "SSE2" HAS_SSE2
!insertmacro CheckCPUExt "$2" "3DNOW" HAS_3DNOW
Goto CPU_DETECTION_DONE
HAS_SSE2:
StrCpy $CPU_TYPE 4 #P4
Goto CPU_DETECTION_DONE
CPU_DETECTION_DONE:
Push $2
Banner::destroy
FunctionEnd
; ---------------------------------------
; Install Sections
; ---------------------------------------
Section ""
Call DetectCPUType
Pop $1
;---------------------------
StrCpy $0 "Unknown / Detection Faild"
StrCmp $CPU_TYPE "2" 0 +2
StrCpy $0 "AMD Athlon (MMX, 3DNow!)"
StrCmp $CPU_TYPE "3" 0 +2
StrCpy $0 "Intel Pentium III (MMX, SSE)"
StrCmp $CPU_TYPE "4" 0 +2
StrCpy $0 "Intel Pentium 4 (MMX, SSE, SSE2)"
StrCmp $CPU_TYPE "5" 0 +2
StrCpy $0 "Runtime CPU Detection (Generic)"
;---------------------------
MessageBox MB_ICONINFORMATION "Your CPU Type is: $0$\t$\nYour CPU Capabilities are: $1"
SectionEnd
Note that you'll need "cpuinfo.exe" from here:
http://oss.netfarm.it/mplayer-win32.php