FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour nee the cpu Id
Posts: 7317
Joined: Thu Oct 18, 2012 07:17 PM
nee the cpu Id
Posted: Sat Nov 08, 2025 01:30 PM

I found this but not run

 
 
 #pragma BEGINDUMP

#include <hbapi.h>
#include <windows.h>

HB_FUNC( GETCPUID )
{
   unsigned int eax = 1, ebx = 0, ecx = 0, edx = 0;

   __asm {
      mov eax, 1
      cpuid
      mov ebx, ebx
      mov edx, edx
   }

   char szID[17];
   wsprintfA( szID, "%08X%08X", ebx, edx );
   hb_retc( szID );
}

#pragma ENDDUMP
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
Posts: 7317
Joined: Thu Oct 18, 2012 07:17 PM
Re: nee the cpu Id
Posted: Sat Nov 08, 2025 01:38 PM

correct because BCC7 does not support __asm ​​{ ... } with local variables

#pragma BEGINDUMP

#include <hbapi.h>
#include <windows.h>

HB_FUNC( GETCPUID )
{
   char szID[17];
   unsigned long ebx, edx;

   // Usa __asm con sintassi BCC7
   _asm {
      mov eax, 1
      cpuid
      mov ebx, ebx
      mov edx, edx
   }

   // Usa variabili locali per ebx, edx
   _asm mov ebx, ebx
   _asm mov edx, edx

   // Formatta come stringa
   wsprintfA( szID, "%08lX%08lX", ebx, edx );
   hb_retc( szID );
}

#pragma ENDDUMP
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
Posts: 670
Joined: Wed Oct 19, 2005 06:41 PM
Re: nee the cpu Id
Posted: Sun Nov 09, 2025 03:11 AM

Silvio good night maybe this ( only windows )

function main()

 ? GetCpuIDHarbour()

return nil

FUNCTION GetCpuIDHarbour()

LOCAL nHandle
LOCAL cCommand := "wmic cpu get ProcessorId"
LOCAL aLines
LOCAL cID
local cLine

local nRet
local cStdOut := space(40)
local cStdErr := space(40)

nRet = hb_processRun( cCommand, , @cStdOut, @cStdErr )
IF Empty( cStdOut )
    RETURN ""
ENDIF

// Procesar la salida. wmic suele devolver una cabecera y el valor.
// Ejemplo de salida:
// ProcessorId
// BFEBFBFF00040671

// Dividir el resultado por lĂ­neas
aLines := hb_aTokens( cStdOut, Chr(13) + Chr(10) )

// La segunda lĂ­nea (Ă­ndice 2, si la cabecera es la 1ra y no hay lĂ­neas vacĂ­as)
// debería contener el ID. Necesitarás limpiar espacios y saltos de línea.
IF Len( aLines ) >= 2
    // El ID suele estar en la segunda línea después de limpiar espacios.
    cID := AllTrim( aLines[ 2 ] )

    // Buscar la línea que no es 'ProcessorId' y no está vacía
    FOR EACH cLine IN aLines
        cLine := AllTrim( cLine )
        IF ! Empty( cLine ) .AND. Upper( cLine ) <> "PROCESSORID"
            RETURN cLine // Este es el ProcessorId
        ENDIF
    NEXT
ENDIF

RETURN ""
Wilson 'W' Gamboa A
Wilson.josenet@gmail.com
Posts: 1054
Joined: Sun Oct 09, 2005 10:41 PM
Re: nee the cpu Id
Posted: Thu Nov 20, 2025 05:28 PM

HI,,,

Function WMainInfo()
LOCAL  oDatos, oSrv, oJob, i
LOCAL    nFree:= ""
LOCAL     oLoc:= CreateObject( "wbemScripting.SwbemLocator" )
LOCAL   objWMI:= oLoc:ConnectServer()

LOCAL oSistema:= objWMI:ExecQuery("Select * from Win32_PhysicalMedia")
LOCAL   oDisco:= objWMI:ExecQuery("Select * from Win32_LogicalDisk")
LOCAL   oParti:= objWMI:ExecQuery("Select * from CIM_DiskPartition")
LOCAL  oDisket:= objWMI:ExecQuery("Select * From Win32_LogicalDisk Where DeviceID = 'A:'")
LOCAL   objUnd:= objWMI:ExecQuery("Select * from Win32_MappedLogicalDisk")
LOCAL     oUnd:= objWMI:ExecQuery("Select * from Win32_CDROMDrive")
LOCAL  oResolu:= objWMI:ExecQuery("Select * from Win32_DesktopMonitor")
LOCAL  oSistem:= objWMI:ExecQuery("Select * from Win32_OperatingSystem")
LOCAL   oUsers:= objWMI:ExecQuery("Select * from Win32_Account")
LOCAL    oServ:= objWMI:ExecQuery("Select * from Win32_Service Where Name = 'Themes'")
LOCAL    oTime:= objWMI:ExecQuery("Select * from Win32_LocalTime")
LOCAL    oProc:= objWMI:ExecQuery("Select * from Win32_Processor")
LOCAL     oJbs:= objWMI:ExecQuery("SELECT Product, SerialNumber FROM Win32_BaseBoard")
LOCAL   oIpSet:= objWMI:ExecQuery("SELECT IPAddress FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled=TRUE")
LOCAL   oList := objWMI:ExecQuery("Select * from Win32_ComputerSystem")

//Return(Nil)
objWMI:= oLoc:ConnectServer()
oJbs := objWMI:ExecQuery( "select * from Win32_BaseBoard" )
//oSrv:ExecQuery( "SELECT * FROM Win32_BaseBoard" )

FOR EACH oDatos IN oJbs
  oApp:tMBrd := Alltrim(cValtoChar(oDatos:Product))
  oApp:sMBrd := Alltrim(cValtoChar(oDatos:SerialNumber))
NEXT

FOR EACH oDatos IN oProc
  oApp:nCpu := Alltrim(cValtoChar(oDatos:Name))
  oApp:vCpu := Alltrim(cValtoChar(oDatos:CurrentClockSpeed)) + " Mghz"
  oApp:iCpu := Alltrim(cValtoChar(oDatos:ProcessorID))                      // aqui esta el ID
NEXT

FOR Each oDatos in oSistem
  oApp:vDOS := oDatos:Caption + " " + oDatos:VERSION
NEXT

Return(NIl)
Posts: 1054
Joined: Sun Oct 09, 2005 10:41 PM
Re: nee the cpu Id
Posted: Thu Nov 20, 2025 05:36 PM

From CMD

Follow the steps below using the search bar in Windows*, located on the bottom of the screen.

Type wmic
Choose the application called wmic
Type cpu get processorid
The last five digits of the number are displayed to represent the CPUID for the processor.

Continue the discussion