nee the cpu Id

Post Reply
User avatar
Silvio.Falconi
Posts: 7348
Joined: Thu Oct 18, 2012 7:17 pm

nee the cpu Id

Post by Silvio.Falconi »

I found this but not run

Code: Select all | Expand

 
 
 #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
User avatar
Silvio.Falconi
Posts: 7348
Joined: Thu Oct 18, 2012 7:17 pm

Re: nee the cpu Id

Post by Silvio.Falconi »

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

Code: Select all | Expand

#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
User avatar
wilsongamboa
Posts: 672
Joined: Wed Oct 19, 2005 6:41 pm
Location: Quito - Ecuador

Re: nee the cpu Id

Post by wilsongamboa »

Silvio good night maybe this ( only windows )

Code: Select all | Expand

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
[email protected]
User avatar
Willi Quintana
Posts: 1070
Joined: Sun Oct 09, 2005 10:41 pm
Location: Cusco - Perú
Contact:

Re: nee the cpu Id

Post by Willi Quintana »

HI,,,

Code: Select all | Expand

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)


User avatar
Willi Quintana
Posts: 1070
Joined: Sun Oct 09, 2005 10:41 pm
Location: Cusco - Perú
Contact:

Re: nee the cpu Id

Post by Willi Quintana »

From CMD

Code: Select all | Expand

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.
Post Reply