how do i get the cpu speed?
thanx in advance
Printable View
how do i get the cpu speed?
thanx in advance
Check this out:
VB Code:
Private Sub Command1_Click() '======================== Dim WMI Dim wmiWin32Objects Dim wmiWin32Object Dim ComputerName As String ComputerName = "PENTIUM21" Set WMI = GetObject("WinMgmts://" & ComputerName) Set wmiWin32Objects = WMI.InstancesOf("Win32_Processor") With wmiWin32Object For Each wmiWin32Object In wmiWin32Objects Debug.Print "AddressWidth: " & .AddressWidth Debug.Print "Architecture: " & .Architecture Debug.Print "Availability: " & .Availability Debug.Print "Caption: " & .Caption Debug.Print "ConfigManagerErrorCode: " & .ConfigManagerErrorCode Debug.Print "ConfigManagerUserConfig: " & .ConfigManagerUserConfig Debug.Print "CpuStatus: " & .CpuStatus Debug.Print "CreationClassName: " & .CreationClassName Debug.Print "CurrentClockSpeed: " & .CurrentClockSpeed Debug.Print "CurrentVoltage: " & .CurrentVoltage Debug.Print "DataWidth: " & .DataWidth Debug.Print "Description: " & .Description Debug.Print "DeviceID: " & .DeviceID Debug.Print "ErrorCleared: " & .ErrorCleared Debug.Print "ErrorDescription: " & .ErrorDescription Debug.Print "ExtClock: " & .ExtClock Debug.Print "Family: " & .Family Debug.Print "InstallDate: " & .InstallDate Debug.Print "L2CacheSize: " & .L2CacheSize Debug.Print "L2CacheSpeed: " & .L2CacheSpeed Debug.Print "LastErrorCode: " & .LastErrorCode Debug.Print "Level: " & .Level Debug.Print "LoadPercentage: " & .LoadPercentage Debug.Print "Manufacturer: " & .Manufacturer Debug.Print "MaxClockSpeed: " & .MaxClockSpeed Debug.Print "Name: " & .Name Debug.Print "OtherFamilyDescription: " & .OtherFamilyDescription Debug.Print "PNPDeviceID: " & .PNPDeviceID Debug.Print "PowerManagementCapabilities: " & .PowerManagementCapabilities Debug.Print "PowerManagementSupported: " & .PowerManagementSupported Debug.Print "ProcessorId: " & .ProcessorId Debug.Print "ProcessorType: " & .ProcessorType Debug.Print "Revision: " & .Revision Debug.Print "Role: " & .Role Debug.Print "SocketDesignation: " & .SocketDesignation Debug.Print "Status: " & .Status Debug.Print "StatusInfo: " & .StatusInfo Debug.Print "Stepping: " & .Stepping Debug.Print "SystemCreationClassName: " & .SystemCreationClassName Debug.Print "SystemName: " & .SystemName Debug.Print "UniqueId: " & .UniqueId Debug.Print "UpgradeMethod: " & .UpgradeMethod Debug.Print "Version: " & .Version Debug.Print "VoltageCaps: " & .VoltageCaps Debug.Print "Description: " & .Description Debug.Print "Manufacturer: " & .Manufacturer Debug.Print "MaxClockSpeed: " & .MaxClockSpeed Next End With End Sub
Just ComputerName to your computer name.
any other ways to do it?
IROY55, can you please explain what is "WinMgmts" and how it works? I never came accross something like that before..:confused:Quote:
Originally posted by IROY55
Check this out:
VB Code:
Set WMI = GetObject("WinMgmts://" & ComputerName)
For more detaied explanation visit MS sites:
http://msdn.microsoft.com/library/de..._processor.asp
http://msdn.microsoft.com/library/de...ng_a_class.asp
but how can you find the speed without using that piece of code. There are other ways or not???
I remember in the old days where I acquire a piece of
QBasic code(that's rite! MS-DOS stuffs), which, it has a DoLoop,
and in the loop it keeps on incrementing a variable(or perhaps
some sort of calculation, I forgot), and after about 5 seconds,
the results are divided by 5 seconds and voila u got the CPU
speed. It's quite accurate, though.
I've also made such thing, but in VB6 and with a nice meter.
This is really sounds silly: DOS is not multitsaking OS, so you may probably calculate somewhat CPU speed, on the other hand Windows is a multitasking OS (or at least pretends to be). Calculating your CPU speed using this method will give you different results depending on how much Resources/CPU/Memory usage, etc.
Jian,
can you describe what you are talking about...
I tried the loop and then divided it by 5 (for 5 seconds) and I get a return of 53195.4 . Now how does that translate to processor of 850 Meg?? ( my PC is a 850)
:confused:
Code:
Dim StartTime
Dim X As Long
X = 0
StartTime = Time
Do Until DateDiff("s", StartTime, Time) >= 5
X = X + 1
DoEvents
Loop
Debug.Print X / 5
Well, if you download the Microsoft SDK, then this answer might
work (though I haven't looked):
http://www.experts-exchange.com/Prog..._20131201.html
Outside of the suggestion listed above in this thread, I don't
think VB can natively retrieve the CPU speed. The way I've
always learned to do it is through a calculation in assembly
(which you could do inline in C/C++ I'm sure).
Pillejunior,
There are several posts on the forum dealing with this subject. I recently made a dll that will get any info I need of a computer.
The bottom line is, if you have a Win9x platform, you can not get the CPU speed unless you create a C++ dll and use some assembly code. I found a dll out there that will give you just the cpu speed. Here is the link
http://www.vbforums.com/showthread.p...light=cpuspeed
The WMI stuff seems to only work on the an NT platform and mainly 2000 and later.
You can get the speed by using the following code on a Win200/XP machine to retrieve the speed from the registry.
VB Code:
Private Const KEY_CREATE_LINK = &H20 Private Const KEY_CREATE_SUB_KEY = &H4 Private Const KEY_ENUMERATE_SUB_KEYS = &H8 Private Const KEY_EVENT = &H1 ' Event contains key event record Private Const KEY_NOTIFY = &H10 Private Const KEY_QUERY_VALUE = &H1 Private Const KEY_SET_VALUE = &H2 Private Const READ_CONTROL = &H20000 Private Const SYNCHRONIZE = &H100000 Private Const STANDARD_RIGHTS_READ = (READ_CONTROL) Private Const STANDARD_RIGHTS_ALL = &H1F0000 Private Const STANDARD_RIGHTS_WRITE = (READ_CONTROL) Private Const KEY_WRITE = ((STANDARD_RIGHTS_WRITE Or KEY_SET_VALUE Or KEY_CREATE_SUB_KEY) And (Not SYNCHRONIZE)) Private Const KEY_ALL_ACCESS = ((STANDARD_RIGHTS_ALL Or KEY_QUERY_VALUE Or _ KEY_SET_VALUE Or KEY_CREATE_SUB_KEY Or _ KEY_ENUMERATE_SUB_KEYS Or KEY_NOTIFY Or _ KEY_CREATE_LINK) And (Not SYNCHRONIZE)) Private Const KEY_READ = ((STANDARD_RIGHTS_READ Or KEY_QUERY_VALUE Or KEY_ENUMERATE_SUB_KEYS Or KEY_NOTIFY) And (Not SYNCHRONIZE)) Private Const KEY_EXECUTE = ((KEY_READ) And (Not SYNCHRONIZE)) Private Const HKEY_LOCAL_MACHINE = &H80000002 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 Declare Function RegOpenKeyEx Lib "advapi32.dll" Alias "RegOpenKeyExA" _ (ByVal hKey As Long, ByVal lpSubKey As String, ByVal ulOptions As Long, _ ByVal samDesired As Long, phkResult As Long) As Long Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long Public Function ProcessorSpeed() As String ' If we are on a WinNT Platform, we can do this Dim lValue As Long Dim GroupHandle As Long Dim Section As String Section = "HARDWARE\DESCRIPTION\System\CentralProcessor\0" ' Open the Registry Key RegOpenKeyEx HKEY_LOCAL_MACHINE, Section, 0&, KEY_READ, GroupHandle ' Get the value RegQueryValueEx GroupHandle, "~Mhz", 0&, 0&, lValue, 4& ' Close the Registry RegCloseKey GroupHandle 'Give it to me ProcessorSpeed = lValue & " Mhz" End Function
I hope this helps you out.
Jerel