Adam Caudill

Security Leader, Researcher, Developer, Writer, & Photographer

Get CPU Speed

This post was imported from an old blog archive, and predates the creation of AdamCaudill.com.

This was created as a request on a forum I’m on, it queries the registry for the speed of the first CPU, adjusting for multiple CPU support would be simple.

Option Explicit

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 Declare Function RegCloseKey Lib "advapi32.dll" ( _
    ByVal hKey As Long _
) As Long

Private Const REG_DWORD = 4
Private Const ERROR_SUCCESS = 0&
Private Const HKEY_LOCAL_MACHINE = &H80000002

Public Function GetCPUSpeed() As Long
Dim lngResult As Long
Dim lngKeyHandle As Long
Dim lngValueType As Long
Dim lngBufferSize As Long
Dim lngBuffer As Long

    lngResult = RegOpenKey(HKEY_LOCAL_MACHINE, "HARDWARE\DESCRIPTION\System\CentralProcessor\0", lngKeyHandle)
    lngResult = RegQueryValueEx(lngKeyHandle, "~MHz", 0&, lngValueType, ByVal 0&, lngBufferSize)
    If lngValueType = REG_DWORD Then
        lngResult = RegQueryValueEx(lngKeyHandle, "~MHz", 0, 0, lngBuffer, lngBufferSize)
        If lngResult = ERROR_SUCCESS Then
            GetCPUSpeed = lngBuffer
        End If
    End If
End Function

Adam Caudill


Related Posts

  • Conexant (formerly Rockwell) Softmodem HSF Modem

    This post was imported from an old blog archive, and predates the creation of AdamCaudill.com. I was actually rather lucky to have this brand of WinModem, as the good people over at Linuxant.com offer a very high quality driver that makes installation a breeze! But, they have recently changed their marketing methods and charge $15 for the driver, so these really lives no viable, free alternative (a rarity to say the least for linux).

  • APISettings

    This post was imported from an old blog archive, and predates the creation of AdamCaudill.com. Visual Basic provides a less than elegant method of saving data in the Windows registry, the GetSetting & SaveSetting functions. These functions store setting in HKEY_CURRENT_USER\Software\VB and VBA Program Settings\<AppName>\<Section> not very pretty is it? The APISettings module is a drop-in replacement using pure Win32 API for its processing power and increased stability. The reason for developing this and for making it drop-in compatible is to all those new to the Win32 API to add its functionality with minimal difficulty.

  • CloseApp

    This post was imported from an old blog archive, and predates the creation of AdamCaudill.com. This is a useful function to close a program based on a windows caption, this should work for any top-level window. Paste all this into a standard module, save it. Then call CloseApp("Notepad") or whatever the name of the window is, it’s nice & simple and should close the program instantly. This requires Windows 2000 plus, for older versions of Windows a different method is required, that isn’t covered here, seeing as Windows 2000 and better require special privileges to forcefully close a program.

  • UPEK Windows Password Decryption

    On August 28th ElcomSoft announced that they had determined a method to extract Windows passwords from the registry for users of UPEK’s fingerprint readers and Protector Suite software (UPEK is now owned by AuthenTec, which is now owned by Apple). What they didn’t announce was the technical details of how they did it. Myself and Brandon Wilson have been working to recreate their research – and we have. We have not been in contact with ElcomSoft, so this is an independent re-discovery of this vulnerability.

  • A month with DuckDuckGo

    It wasn’t long after Google went live that they became my search engine of choice – with the only other (somewhat) viable option being Yahoo, it was an easy choice. In the years since then, I’ve not questioned that choice, but now that Google is focusing on killing features and building little-used social features, the time seemed right to see if there are better options. So a month ago I began an experiment, I committed to using DuckDuckGo for a month – here’s what I’ve found.