2010-03-23 116 views

Respuesta

16

intente utilizar el WMI Win32_BaseBoard Class.

ver tesis muestras:

opción 1) antes de ejecutar lo que necesita importar el Microsoft WMIScripting Library de Component ->Import Component y luego seleccione Import type library

program GetWMI_MotherBoardInfo; 

{$APPTYPE CONSOLE} 

uses 
    ActiveX, 
    Variants, 
    SysUtils, 
    WbemScripting_TLB in '..\..\..\Documents\RAD Studio\5.0\Imports\WbemScripting_TLB.pas';// 


Function GetMotherBoardSerial:string; 
var 
    WMIServices : ISWbemServices; 
    Root  : ISWbemObjectSet; 
    Item  : Variant; 
begin 
    WMIServices := CoSWbemLocator.Create.ConnectServer('.', 'root\cimv2','', '', '', '', 0, nil); 
    Root := WMIServices.ExecQuery('Select SerialNumber From Win32_BaseBoard','WQL', 0, nil); 
    Item := Root.ItemIndex(0); 
    Result:=VarToStr(Item.SerialNumber); 
end; 


begin 
    try 
    CoInitialize(nil); 
    Writeln('Serial MotherBoard '+GetMotherBoardSerial); 
    Readln; 
    CoUninitialize; 
    except 
    on E:Exception do 
    Begin 
     CoUninitialize; 
     Writeln(E.Classname, ': ', E.Message); 
     Readln; 
    End; 
    end; 
end. 

Opción 2) usando OLEVariant, IBindCtx Interface y IMoniker Interface

program GetWMI_MotherBoardSerial; 

{$APPTYPE CONSOLE} 

uses 
    SysUtils 
    ,ActiveX 
    ,ComObj 
    ,Variants; 


function GetMotherBoardSerial:String; 
var 
    objWMIService : OLEVariant; 
    colItems  : OLEVariant; 
    colItem  : OLEVariant; 
    oEnum   : IEnumvariant; 
    iValue  : LongWord; 

    function GetWMIObject(const objectName: String): IDispatch; 
    var 
    chEaten: Integer; 
    BindCtx: IBindCtx; 
    Moniker: IMoniker; 
    begin 
    OleCheck(CreateBindCtx(0, bindCtx)); 
    OleCheck(MkParseDisplayName(BindCtx, StringToOleStr(objectName), chEaten, Moniker)); 
    OleCheck(Moniker.BindToObject(BindCtx, nil, IDispatch, Result)); 
    end; 

begin 
    Result:=''; 
    objWMIService := GetWMIObject('winmgmts:\\localhost\root\cimv2'); 
    colItems  := objWMIService.ExecQuery('SELECT SerialNumber FROM Win32_BaseBoard','WQL',0); 
    oEnum   := IUnknown(colItems._NewEnum) as IEnumVariant; 
    if oEnum.Next(1, colItem, iValue) = 0 then 
    Result:=VarToStr(colItem.SerialNumber); 
end; 


begin 
try 
    CoInitialize(nil); 
    try 
     Writeln('Serial MotherBoard '+GetMotherBoardSerial); 
     Readln; 
    finally 
    CoUninitialize; 
    end; 
except 
    on E:Exception do 
    Begin 
     Writeln(E.Classname, ': ', E.Message); 
     Readln; 
    End; 
    end; 
end. 
+2

ur el hombre RRUZ, aprenderán algo :) – radick

+0

@PRUZ, se puede explicar el segundo código ... Funciona pero quiero alguna explicación. – Himadri

+0

Lo único que no entendí es 'winmgmts: \\ localhost \ root \ cimv2' – Himadri

0

tengo otra solución:

function TForm1.GetSerialMotherBoard: String; 
var 
    a, b, c, d: LongWord; 
begin 
    asm 
    push EAX 
    push EBX 
    push ECX 
    push EDX 

    mov eax, 1 
    db $0F, $A2 
    mov a, EAX 
    mov b, EBX 
    mov c, ECX 
    mov d, EDX 

    pop EDX 
    pop ECX 
    pop EBX 
    pop EAX 

    end; 
    result := inttohex(a, 8) + '-' + 
      inttohex(b, 8) + '-' + 
      inttohex(c, 8) + '-' + 
      inttohex(d, 8); 
end; 

Saludos Wellington

+0

¿Puede explicarme qué está haciendo su código? ¿Estás seguro de que devuelve el número de serie de la placa base, pero no el CPUID? –

+0

Leí un montón de problemas al respecto y concluí que no hay una identificación para la CPU y cambio mi propuesta para obtener la ID del HDD. Mi programa anterior capta la misma ID en diferentes computadoras. –

Cuestiones relacionadas