|
-
Oct 18th, 2002, 12:45 PM
#1
Thread Starter
Lively Member
cpu speed
how do i get the cpu speed?
thanx in advance
-
Oct 18th, 2002, 12:56 PM
#2
PowerPoster
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
-
Oct 18th, 2002, 12:56 PM
#3
PowerPoster
Just ComputerName to your computer name.
-
Oct 21st, 2002, 05:56 AM
#4
Thread Starter
Lively Member
-
Oct 21st, 2002, 06:31 AM
#5
-
Oct 21st, 2002, 07:19 AM
#6
Hyperactive Member
Originally posted by IROY55
Check this out:
VB Code:
Set WMI = GetObject("WinMgmts://" & ComputerName)
IROY55, can you please explain what is "WinMgmts" and how it works? I never came accross something like that before..
-
Oct 21st, 2002, 07:29 AM
#7
PowerPoster
-
Oct 22nd, 2002, 06:38 AM
#8
Thread Starter
Lively Member
but how can you find the speed without using that piece of code. There are other ways or not???
-
Oct 22nd, 2002, 06:42 AM
#9
Fanatic Member
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.
ASM,C,C++,BASIC,VB,JAVA,VBS,HTML,ASP,PHP,mySQL,VB.NET,MATLAB
Programming is fun, but only if you're not on a tight deadline 
So I consider all those working engineers sad people
VB FTP class
3 page PHP crash course
Crash Course on DX9 Managed with VB.NET covering basics till terrain creation
-
Oct 22nd, 2002, 07:01 AM
#10
Fanatic Member
I've also made such thing, but in VB6 and with a nice meter.
-
Oct 22nd, 2002, 07:26 AM
#11
PowerPoster
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.
-
Oct 22nd, 2002, 09:13 AM
#12
Frenzied Member
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)
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
10 different ways to skin a cat and amazingly enough each and every one has the same result, the cat gets skinned! The same can be applied to code, so be nice and accept each others "preferences".
-
Oct 22nd, 2002, 12:23 PM
#13
Addicted Member
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).
-
Oct 22nd, 2002, 01:07 PM
#14
Hyperactive Member
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
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
|