Detect OS, 64 bit, hyper-threading

Coordinator
Mar 31, 2011 at 7:39 PM
Edited Mar 31, 2011 at 7:42 PM

http://thetechconsult.com/demo/default.aspx?action=hyper


* To try this, just place in main.prg as another CASE clause
CASE oProp.Action=='hyper'
        * First get OS and 64-bit info
        lcOS = OS(1)
        DO CASE
        CASE "6.01" $ lcOS AND OS(11) = "1"
	    lcPlatform = "WIN7"
        CASE "6.01" $ lcOS
	    lcPlatform = "WIN2008R2"
        CASE "6.00" $ lcOS AND OS(11) = "1"
	    lcPlatform = "VISTA"
        CASE "6.00" $ lcOS
	    lcPlatform = "WIN2008"
        CASE "5.02" $ lcOS
	    lcPlatform = "WIN2003"
        CASE "5.01" $ lcOS
	    lcPlatform = "WINXP"
        CASE "5.0" $ lcOS
	    lcPlatform = "WIN2000"
        OTHERWISE
	    lcPlatform = lcOS
        ENDCASE
        oResponse.Write( "Operating System:"+ lcPlatform+"<BR>") 

        * Determine if IsWow64Process function exists in the OS we're running under
        DECLARE Long GetModuleHandle IN WIN32API STRING lpModuleName
        DECLARE Long GetProcAddress IN WIN32API Long hModule, String lpProcName
        llIsWow64ProcessExists = (GetProcAddress(GetModuleHandle("kernel32"),"IsWow64Process") <> 0)
 
        llIs64BitOS = .F.
        IF llIsWow64ProcessExists 
	    DECLARE Long GetCurrentProcess IN WIN32API 
	    DECLARE Long IsWow64Process IN WIN32API Long hProcess, Long @ Wow64Process
	    lnIsWow64Process = 0
	    * IsWow64Process function return value is nonzero if it succeeds 
	    * The second output parameter value will be nonzero if VFP application is running under 64-bit OS 
	    IF IsWow64Process( GetCurrentProcess(), @lnIsWow64Process) <> 0
		llIs64BitOS = (lnIsWow64Process <> 0)
	    ENDIF	
        ENDIF	
        oResponse.Write( IIF(llIs64BitOS , [64-bit],[32-bit])+"<BR>")
	
        * Use WMI to determine if HyperThreading is turned on
	* This only works on Windows XP SP3, Windows Server 2003, and later because
	*	underlying Windows APIs were not added until those versions.
	Local lcWMIFolder, loWMI, lcolProcessors, loProcessor
        lcHTMLout=[]
	lcWMIFolder = Addbs(GetEnv("SystemRoot")) + "System32\WBEM\"
	If Directory(lcWMIFolder)	&& make sure installed
	loWMI = GetObject("winmgmts:\\.\root\cimv2")
	lcolProcessors = loWMI.ExecQuery("Select * from Win32_Processor")
	For each loProcessor in lcolProcessors FoxObject
		If Type("loProcessor.NumberOfCores")<> "U" and Type("loProcessor.NumberOfLogicalProcessors")<> "U"
			oResponse.Write( "CPU Manufacturer:"+ loProcessor.Manufacturer+"<BR>")
			oResponse.Write( "CPU Name:"+ loProcessor.Name+"<BR>")
			oResponse.Write( "Number of Physical Cores:"+TRANS(loProcessor.NumberOfCores)+"<BR>")
			oResponse.Write( "Number of Logical Processors:"+ TRANS(loProcessor.NumberOfLogicalProcessors)+"<BR>")
			* If logical processors > actual cores, HT must be turned on
			If loProcessor.NumberOfLogicalProcessors > loProcessor.NumberOfCores
				oResponse.Write( "HyperThreading is ENABLED<BR>")
			Else
				oResponse.Write( "HyperThreading is DISABLED or unavailable on CPU<BR>")
			EndIf 
		Else
			oResponse.Write( "HyperThreading detection not available on this O/S<BR>")
		EndIf 
	EndFor 
	Else
		oResponse.Write( "WMI is not installed.<BR>")
	EndIf