|
-
Nov 29th, 1999, 12:17 PM
#1
Thread Starter
PowerPoster
-
Nov 29th, 1999, 12:34 PM
#2
-
Nov 29th, 1999, 12:41 PM
#3
Thread Starter
PowerPoster
WITHOUT PREDUJICE (important!)
Don't like Microsoft much do you! 
I suggested beating Bill Gates up a while ago, but lack of enthuiasm led to drive-by-shooting being called off!
by the way Mr. Lawyer, Mr. Policeman or anything else Mr. Important, I'm joking!! No drive by shootings have been arranged - certainly not by me. And I didn't attempt to beat him up either - I dunno where he lives!
-
Nov 29th, 1999, 07:23 PM
#4
Sure! Here is a small example of using this API. Add a ListBox (List1) and CommandButton (Command1) to the form and copy this code:
Code:
Private Type SYSTEM_INFO
dwOemID As Long
dwPageSize As Long
lpMinimumApplicationAddress As Long
lpMaximumApplicationAddress As Long
dwActiveProcessorMask As Long
dwNumberOrfProcessors As Long
dwProcessorType As Long
dwAllocationGranularity As Long
dwReserved As Long
End Type
Private Declare Sub GetSystemInfo Lib "kernel32" (lpSystemInfo As SYSTEM_INFO)
Private Const PROCESSOR_INTEL_386 = 386
Private Const PROCESSOR_INTEL_486 = 486
Private Const PROCESSOR_INTEL_PENTIUM = 586
Private Sub Command1_Click()
Dim tSysInfo As SYSTEM_INFO
Dim strProcType As String
Call GetSystemInfo(tSysInfo)
Select Case tSysInfo.dwProcessorType
Case PROCESSOR_INTEL_386
strProcType = "Intel 386"
Case PROCESSOR_INTEL_486
strProcType = "Intel 486"
Case PROCESSOR_INTEL_PENTIUM
strProcType = "Intel Pentium"
End Select
List1.AddItem "Number of processors: " & tSysInfo.dwNumberOrfProcessors
List1.AddItem "Processor Type: " & strProcType
List1.AddItem "Minimum application address: " & tSysInfo.lpMinimumApplicationAddress
List1.AddItem "Maximum application address: " & tSysInfo.lpMaximumApplicationAddress
End Sub
------------------
Serge
Software Developer
[email protected]
[email protected]
ICQ#: 51055819
-
Nov 29th, 1999, 07:38 PM
#5
Addicted Member
Hi Serge..
2 Q's:
1- How about the different generations of Pentiums. (e.g. P1,P2...)?
2- Is this procedure good enough to check the processor wether it's oreginal Or Not?
As always, Thanx.
-
Nov 29th, 1999, 11:27 PM
#6
Next code will definetely will work on WinNT, but may not work on Win95/98 (can't test it right now, don't have it here at work). Add a Listbox (List1) and a CommandButton (Command1) to the form.
Module Code
Code:
Private 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
Private Declare Sub GetSystemInfo Lib "kernel32" (lpSystemInfo As SYSTEM_INFO)
Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
Private Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Private Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, lpData As Any, lpcbData As Long) As Long
Private Const HKEY_LOCAL_MACHINE As Long = &H80000002
Private Const PROCESSOR_INTEL_386 = 386
Private Const PROCESSOR_INTEL_486 = 486
Private Const PROCESSOR_INTEL_PENTIUM = 586
Private Const PROCESSOR_LEVEL_80386 As Long = 3
Private Const PROCESSOR_LEVEL_80486 As Long = 4
Private Const PROCESSOR_LEVEL_PENTIUM As Long = 5
Private Const PROCESSOR_LEVEL_PENTIUMII As Long = 6
Public Type udtCPU
lClockSpeed As Long
lProcType As Integer
strProcLevel As String
strProcRevision As String
lNumberOfProcessors As Long
End Type
Public Function GetCPUInfo(ptCPUInfo As udtCPU)
Dim tSYS As SYSTEM_INFO
Dim intProcType As Integer
Dim strProcLevel As String
Dim strProcRevision As String
Call GetSystemInfo(tSYS)
Select Case tSYS.dwProcessorType
Case PROCESSOR_INTEL_386: intProcType = 386
Case PROCESSOR_INTEL_486: intProcType = 486
Case PROCESSOR_INTEL_PENTIUM: intProcType = 586
End Select
Select Case tSYS.wProcessorLevel
Case PROCESSOR_LEVEL_80386: strProcLevel = "Intel 80386"
Case PROCESSOR_LEVEL_80486: strProcLevel = "Intel 80486"
Case PROCESSOR_LEVEL_PENTIUM: strProcLevel = "Intel Pentium"
Case PROCESSOR_LEVEL_PENTIUMII: strProcLevel = "Intel Pentium Pro or Pentium II"
End Select
strProcRevision = "Model " & HiByte(tSYS.wProcessorRevision) & ", Stepping " & LoByte(tSYS.wProcessorRevision)
With ptCPUInfo
.lClockSpeed = GetCPUSpeed
.lNumberOfProcessors = tSYS.dwNumberOfProcessors
.lProcType = intProcType
.strProcLevel = IIf(strProcLevel = "", "None", strProcLevel)
.strProcRevision = IIf(strProcRevision = "", "None", strProcRevision)
End With
End Function
Public Function HiByte(ByVal wParam As Integer) As Byte
HiByte = (wParam And &HFF00&) \ (&H100)
End Function
Public Function LoByte(ByVal wParam As Integer) As Byte
LoByte = wParam And &HFF&
End Function
Private Function GetCPUSpeed() As Long
Dim hKey As Long
Dim lClockSpeed As Long
Dim strKey As String
strKey = "HARDWARE\DESCRIPTION\System\CentralProcessor\0"
Call RegOpenKey(HKEY_LOCAL_MACHINE, strKey, hKey)
Call RegQueryValueEx(hKey, "~MHz", 0, 0, lClockSpeed, 4)
Call RegCloseKey(hKey)
GetCPUSpeed = lClockSpeed
End Function
Form Code
Code:
Private Sub Command1_Click()
Dim tCPU As udtCPU
Call GetCPUInfo(tCPU)
List1.AddItem "CPU Type: " & tCPU.lProcType
List1.AddItem "Number ofCPUs: " & tCPU.lNumberOfProcessors
List1.AddItem "CPU Level: " & tCPU.strProcLevel
List1.AddItem "CPU Revision: " & tCPU.strProcRevision
List1.AddItem "CPU Speed (Approx): " & tCPU.lClockSpeed
End Sub
I'll make it to work on Win95/98 when I come back home.
------------------
Serge
Software Developer
[email protected]
[email protected]
ICQ#: 51055819
-
Nov 30th, 1999, 11:51 AM
#7
Thread Starter
PowerPoster
-
Nov 30th, 1999, 11:58 AM
#8
Thread Starter
PowerPoster
-
Nov 30th, 1999, 12:08 PM
#9
Thread Starter
PowerPoster
-
Nov 30th, 1999, 05:24 PM
#10
Hyperactive Member
I have the same as chrisjk...
A cpu speed of 0... Tried it on two win98 machines...
-
Nov 30th, 1999, 07:17 PM
#11
Yep...approximate speed of CPU speed is stored in the registry (WinNT only). Windows95/98 don't have that and there's no direct way of finding that out (No API or atleast I couldn't find one).
For API declaration:
VB's API viewer has the wrong declaration of a SYSTEM_INFO structure (maybe it's not the wrong one, but the way it's declared, it won't give you the CPU level and revision).
Look at this C declaration of the SYSTEM_INFO:
Code:
typedef struct _SYSTEM_INFO {
union {
DWORD dwOemId;
struct {
WORD wProcessorArchitecture;
WORD wReserved;
};
};
DWORD dwPageSize;
LPVOID lpMinimumApplicationAddress;
LPVOID lpMaximumApplicationAddress;
DWORD dwActiveProcessorMask;
DWORD dwNumberOfProcessors;
DWORD dwProcessorType;
DWORD dwAllocationGranularity;
WORD wProcessorLevel;
WORD wProcessorRevision;
} SYSTEM_INFO;
Now, look at the API's viewer declaration:
Code:
Private Type SYSTEM_INFO
dwOemID As Long
dwPageSize As Long
lpMinimumApplicationAddress As Long
lpMaximumApplicationAddress As Long
dwActiveProcessorMask As Long
dwNumberOrfProcessors As Long
dwProcessorType As Long
dwAllocationGranularity As Long
dwReserved As Long
End Type
Notice in C declaration the Union keyword? It tells the compiler that the element of that structure would be either the dwOemId or the structure of wProcessorArchitecture and wReserved (It will take the biggest value for the memory storage), BUT...VB doesn't have that luxury. (Using Union), plus in MSDN Library it says that dwOemId is obsolete, which is true but it won't work without it in VB. So, it was just a matter of time porting this declaration to VB. Once again....always use MSDN....sometimes it has all the answers, sometimes not.
------------------
Serge
Software Developer
[email protected]
[email protected]
ICQ#: 51055819
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|