Results 1 to 14 of 14

Thread: cpu speed

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Mar 2002
    Location
    The Netherlands
    Posts
    64

    cpu speed

    how do i get the cpu speed?

    thanx in advance

  2. #2
    PowerPoster
    Join Date
    Aug 2002
    Location
    NY, NY
    Posts
    2,139
    Check this out:
    VB Code:
    1. Private Sub Command1_Click()
    2. '========================
    3. Dim WMI
    4. Dim wmiWin32Objects
    5. Dim wmiWin32Object
    6. Dim ComputerName As String
    7.  
    8.     ComputerName = "PENTIUM21"
    9.     Set WMI = GetObject("WinMgmts://" & ComputerName)
    10.  
    11.     Set wmiWin32Objects = WMI.InstancesOf("Win32_Processor")
    12.     With wmiWin32Object
    13.         For Each wmiWin32Object In wmiWin32Objects
    14.             Debug.Print "AddressWidth: " & .AddressWidth
    15.             Debug.Print "Architecture: " & .Architecture
    16.             Debug.Print "Availability: " & .Availability
    17.             Debug.Print "Caption: " & .Caption
    18.             Debug.Print "ConfigManagerErrorCode: " & .ConfigManagerErrorCode
    19.             Debug.Print "ConfigManagerUserConfig: " & .ConfigManagerUserConfig
    20.             Debug.Print "CpuStatus: " & .CpuStatus
    21.             Debug.Print "CreationClassName: " & .CreationClassName
    22.             Debug.Print "CurrentClockSpeed: " & .CurrentClockSpeed
    23.             Debug.Print "CurrentVoltage: " & .CurrentVoltage
    24.             Debug.Print "DataWidth: " & .DataWidth
    25.             Debug.Print "Description: " & .Description
    26.             Debug.Print "DeviceID: " & .DeviceID
    27.             Debug.Print "ErrorCleared: " & .ErrorCleared
    28.             Debug.Print "ErrorDescription: " & .ErrorDescription
    29.             Debug.Print "ExtClock: " & .ExtClock
    30.             Debug.Print "Family: " & .Family
    31.             Debug.Print "InstallDate: " & .InstallDate
    32.             Debug.Print "L2CacheSize: " & .L2CacheSize
    33.             Debug.Print "L2CacheSpeed: " & .L2CacheSpeed
    34.             Debug.Print "LastErrorCode: " & .LastErrorCode
    35.             Debug.Print "Level: " & .Level
    36.             Debug.Print "LoadPercentage: " & .LoadPercentage
    37.             Debug.Print "Manufacturer: " & .Manufacturer
    38.             Debug.Print "MaxClockSpeed: " & .MaxClockSpeed
    39.             Debug.Print "Name: " & .Name
    40.             Debug.Print "OtherFamilyDescription: " & .OtherFamilyDescription
    41.             Debug.Print "PNPDeviceID: " & .PNPDeviceID
    42.             Debug.Print "PowerManagementCapabilities: " & .PowerManagementCapabilities
    43.             Debug.Print "PowerManagementSupported: " & .PowerManagementSupported
    44.             Debug.Print "ProcessorId: " & .ProcessorId
    45.             Debug.Print "ProcessorType: " & .ProcessorType
    46.             Debug.Print "Revision: " & .Revision
    47.             Debug.Print "Role: " & .Role
    48.             Debug.Print "SocketDesignation: " & .SocketDesignation
    49.             Debug.Print "Status: " & .Status
    50.             Debug.Print "StatusInfo: " & .StatusInfo
    51.             Debug.Print "Stepping: " & .Stepping
    52.             Debug.Print "SystemCreationClassName: " & .SystemCreationClassName
    53.             Debug.Print "SystemName: " & .SystemName
    54.             Debug.Print "UniqueId: " & .UniqueId
    55.             Debug.Print "UpgradeMethod: " & .UpgradeMethod
    56.             Debug.Print "Version: " & .Version
    57.             Debug.Print "VoltageCaps: " & .VoltageCaps
    58.             Debug.Print "Description: " & .Description
    59.             Debug.Print "Manufacturer: " & .Manufacturer
    60.             Debug.Print "MaxClockSpeed: " & .MaxClockSpeed
    61.         Next
    62.     End With
    63.  
    64. End Sub
    Roy

  3. #3
    PowerPoster
    Join Date
    Aug 2002
    Location
    NY, NY
    Posts
    2,139
    Just ComputerName to your computer name.
    Roy

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Mar 2002
    Location
    The Netherlands
    Posts
    64
    any other ways to do it?

  5. #5
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

  6. #6
    Hyperactive Member abhid's Avatar
    Join Date
    Nov 2001
    Location
    3rd rock from the sun
    Posts
    467
    Originally posted by IROY55
    Check this out:
    VB Code:
    1. 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..

  7. #7
    PowerPoster
    Join Date
    Aug 2002
    Location
    NY, NY
    Posts
    2,139
    Roy

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Mar 2002
    Location
    The Netherlands
    Posts
    64
    but how can you find the speed without using that piece of code. There are other ways or not???

  9. #9
    Fanatic Member jian2587's Avatar
    Join Date
    Aug 2000
    Location
    I bet u need a fusion powered shuttle to reach my place...
    Posts
    963
    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

  10. #10
    Fanatic Member petrus's Avatar
    Join Date
    May 2002
    Location
    pBytes[sizeof(pBytes)/2]
    Posts
    553
    I've also made such thing, but in VB6 and with a nice meter.
    ICQ: 128716725

  11. #11
    PowerPoster
    Join Date
    Aug 2002
    Location
    NY, NY
    Posts
    2,139
    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.
    Roy

  12. #12
    Frenzied Member RudyL's Avatar
    Join Date
    Mar 2001
    Location
    Chicago
    Posts
    1,519
    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".

  13. #13
    Addicted Member
    Join Date
    Jul 2002
    Posts
    234
    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).

  14. #14
    Hyperactive Member
    Join Date
    Jun 2002
    Location
    Tulsa,Ok
    Posts
    262
    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:
    1. Private Const KEY_CREATE_LINK = &H20
    2. Private Const KEY_CREATE_SUB_KEY = &H4
    3. Private Const KEY_ENUMERATE_SUB_KEYS = &H8
    4. Private Const KEY_EVENT = &H1     '  Event contains key event record
    5. Private Const KEY_NOTIFY = &H10
    6. Private Const KEY_QUERY_VALUE = &H1
    7. Private Const KEY_SET_VALUE = &H2
    8. Private Const READ_CONTROL = &H20000
    9. Private Const SYNCHRONIZE = &H100000
    10. Private Const STANDARD_RIGHTS_READ = (READ_CONTROL)
    11. Private Const STANDARD_RIGHTS_ALL = &H1F0000
    12. Private Const STANDARD_RIGHTS_WRITE = (READ_CONTROL)
    13. Private Const KEY_WRITE = ((STANDARD_RIGHTS_WRITE Or KEY_SET_VALUE Or KEY_CREATE_SUB_KEY) And (Not SYNCHRONIZE))
    14. Private Const KEY_ALL_ACCESS = ((STANDARD_RIGHTS_ALL Or KEY_QUERY_VALUE Or _
    15.                               KEY_SET_VALUE Or KEY_CREATE_SUB_KEY Or _
    16.                               KEY_ENUMERATE_SUB_KEYS Or KEY_NOTIFY Or _
    17.                               KEY_CREATE_LINK) And (Not SYNCHRONIZE))
    18. Private Const KEY_READ = ((STANDARD_RIGHTS_READ Or KEY_QUERY_VALUE Or KEY_ENUMERATE_SUB_KEYS Or KEY_NOTIFY) And (Not SYNCHRONIZE))
    19. Private Const KEY_EXECUTE = ((KEY_READ) And (Not SYNCHRONIZE))
    20.  
    21. Private Const HKEY_LOCAL_MACHINE = &H80000002
    22.  
    23. Private Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" _
    24.   (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, _
    25.   lpType As Long, lpData As Any, lpcbData As Long) As Long
    26. Private Declare Function RegOpenKeyEx Lib "advapi32.dll" Alias "RegOpenKeyExA" _
    27.   (ByVal hKey As Long, ByVal lpSubKey As String, ByVal ulOptions As Long, _
    28.   ByVal samDesired As Long, phkResult As Long) As Long
    29. Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
    30.  
    31. Public Function ProcessorSpeed() As String
    32.  
    33. ' If we are on a WinNT Platform, we can do this
    34.  
    35.     Dim lValue As Long
    36.     Dim GroupHandle As Long
    37.     Dim Section As String
    38.    
    39.     Section = "HARDWARE\DESCRIPTION\System\CentralProcessor\0"
    40.    
    41.     ' Open the Registry Key
    42.     RegOpenKeyEx HKEY_LOCAL_MACHINE, Section, 0&, KEY_READ, GroupHandle
    43.    
    44.     ' Get the value
    45.     RegQueryValueEx GroupHandle, "~Mhz", 0&, 0&, lValue, 4&
    46.  
    47.     ' Close the Registry
    48.     RegCloseKey GroupHandle
    49.    
    50.     'Give it to me
    51.     ProcessorSpeed = lValue & " Mhz"
    52.  
    53.  
    54. 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
  •  



Click Here to Expand Forum to Full Width