Link to home
Start Free TrialLog in
Avatar of ginsonic
ginsonicFlag for Romania

asked on

Read BIOS and harddisk serial numbers

Delphi:
How can read the Bios and harddisk serial numbers ?
I can find a component for these ?
Avatar of ginsonic
ginsonic
Flag of Romania image

ASKER

Edited text of question
Avatar of inthe
inthe

https://www.experts-exchange.com/Q.10108781
for harddisk
Regards Barry
ASKER CERTIFIED SOLUTION
Avatar of inthe
inthe

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Sorry , but I can find the Bios s.n. .
The component is cool , but I need Bios s.n. to protect my programme .
Maybe I don't search the good component , but ASPowerTools don't have Bios s.n. option , only hard disk s.n. .
Can you tell me more ?

Best regards ,
Nick
First -sorry i thought it did retrieve bios s/n
Second -here's more info
The MB/Bios S/N is not unique,it is only a batch number. Several boards  have the same number if they
-have the same manufacturer.
- have the same revision level
- have the same BIOS date and BIOS model (eg. AMI, Award, Phoenix, Mr. BIos,etc. )So if you were installing your software at a company who purchased there pc's in batch it is possible they will have the same s/n.it would also be extrmely difficult  to get this batch number,probably the best thing is to get motherboard s/n as well as hard disk s/n with other info and combine them.the hard disk number is set when the disk is formatted based on the time and it is not likely 2 people are formatting there disks at identical times.
the best number to get would be the "mac address" (pc's network ethernet address) as in nearly all cases it is unique but then only if the pc's are on a network.
i post some code below for what is possible to read from the cmos it was wrote by Earl Glynn of efg's computer lab
http://infomaster.net/external/efg

Here's a Delphi 3 example that fetches some of the CMOS information and gets
the date and time using the "old" BIOS interrupts.  (This was adapted from
some old TP 7 code, so I didn't bother using "newer" Delphi functions for
conversions.)


unit ScreenCMOS;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, Spin;

type
  TForm1 = class(TForm)
    ButtonCMOSInfo: TButton;
    Memo1: TMemo;
    ButtonReadClock: TButton;
    SpinEditCentury: TSpinEdit;
    SpinEditYear: TSpinEdit;
    SpinEditMonth: TSpinEdit;
    SpinEditHours: TSpinEdit;
    SpinEditMinutes: TSpinEdit;
    SpinEditSeconds: TSpinEdit;
    SpinEditDay: TSpinEdit;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    Label7: TLabel;
    Label8: TLabel;
    ButtonSetClock: TButton;
    procedure ButtonCMOSInfoClick(Sender: TObject);
    procedure ButtonReadClockClick(Sender: TObject);
    procedure ButtonSetClockClick(Sender: TObject);
  private
    PROCEDURE CMOSSummary;
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;


implementation
{$R *.DFM}

////////////////////////////////////////////////////////////////////////////

  //  Note:  PortIn and PortOut will work in Windows 95, but will NOT work
  //         under Windows NT.

  FUNCTION PortIn(IOport:  WORD):  BYTE;  ASSEMBLER; REGISTER;
  ASM
    MOV    DX,AX
    IN     AL,DX
  END;


  PROCEDURE PortOut(IOport:  WORD;  Value:  BYTE);  ASSEMBLER; REGISTER;
  ASM
     XCHG   DX,AX
     OUT    DX,AL
  END;

////////////////////////////////////////////////////////////////////////////

  FUNCTION B2X(CONST b:  BYTE):  STRING;  {byte-to-hexadecimal}
    CONST HexDigit:  ARRAY[0..15] OF CHAR = '0123456789ABCDEF';
  BEGIN
    RESULT :=  HexDigit[b SHR 4] + HexDigit[b AND $0F]
  END {B2X};


  FUNCTION C2X(CONST s:  STRING):  STRING;  {character-to-hexadecimal}
    VAR
      i:  BYTE;
      t:  STRING;
  BEGIN
    t := '';
    FOR i := 1 TO LENGTH(s) DO
    BEGIN
      AppendStr(t, B2X( BYTE(s[i]) ));
    END;
    RESULT := t
  END {C2X};


  PROCEDURE TForm1.CMOSsummary;
    VAR
      i,j,k:  BYTE;
      line :  STRING[16];
      hex  :  STRING[32];
  BEGIN
    Memo1.Lines.Add('CMOS RAM Memory');
    Memo1.Lines.Add ('   . . . . | . . . . | . . . . | .
..|....|....|.');
    k := 0;
    FOR j := 1 TO 4 DO BEGIN
      line := '';
      FOR i := 1 TO 16 DO BEGIN
        PORTOut($70,k);
        line := line + CHR(PORTIn($71));
        INC (k);
      END;
      hex := C2X(line);
      FOR i := 1 TO 16 DO
        IF   NOT (line[i] IN [#$20..#$7E])
        THEN line[i] := '.';           {an 'unprintable' character}
      Memo1.Lines.Add ('  ' + hex + '  ' + line)
    END
  END;


procedure TForm1.ButtonCMOSInfoClick(Sender: TObject);
begin
  CMOSSummary
end;


FUNCTION BCDToInt(bcd:  BYTE):  INTEGER;
BEGIN
  RESULT := 10*(bcd SHR 4) + (bcd AND $0F)
END;


FUNCTION IntToBCD(i:  INTEGER):  BYTE;
BEGIN
  RESULT := 16*(i DIV 10) + (i MOD 10)
END;



// See IBM ROM BIOS by Ray Duncan, Microsoft Press, 1988
PROCEDURE GetCMOSDate(VAR Day, Month, Year, Century:  BYTE);  PASCAL;
BEGIN
  // All values returned are BCD -- binary-coded decimal
  asm
    MOV AH,$04
    INT $1A        // BIOS Call:  Read date from real-time clock

    MOV EAX,Century
    MOV [EAX],CH

    MOV EAX,Year
    MOV [EAX],CL

    MOV EAX,Month
    MOV [EAX],DH

    MOV EAX,Day
    MOV [EAX],DL
  end;

  // Convert from BCD to binary
  Century := BCDToInt(Century);
  Year := BCDToInt(Year);
  Month := BCDToInt(Month);
  Day := BCDTOInt(Day)
END;

Regards Barry



sorry i missed half out here is full unit:

unit ScreenCMOS;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, Spin;

type
  TForm1 = class(TForm)
    ButtonCMOSInfo: TButton;
    Memo1: TMemo;
    ButtonReadClock: TButton;
    SpinEditCentury: TSpinEdit;
    SpinEditYear: TSpinEdit;
    SpinEditMonth: TSpinEdit;
    SpinEditHours: TSpinEdit;
    SpinEditMinutes: TSpinEdit;
    SpinEditSeconds: TSpinEdit;
    SpinEditDay: TSpinEdit;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    Label7: TLabel;
    Label8: TLabel;
    ButtonSetClock: TButton;
    procedure ButtonCMOSInfoClick(Sender: TObject);
    procedure ButtonReadClockClick(Sender: TObject);
    procedure ButtonSetClockClick(Sender: TObject);
  private
    PROCEDURE CMOSSummary;
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;


implementation
{$R *.DFM}

////////////////////////////////////////////////////////////////////////////

  //  Note:  PortIn and PortOut will work in Windows 95, but will NOT work
  //         under Windows NT.

  FUNCTION PortIn(IOport:  WORD):  BYTE;  ASSEMBLER; REGISTER;
  ASM
    MOV    DX,AX
    IN     AL,DX
  END;


  PROCEDURE PortOut(IOport:  WORD;  Value:  BYTE);  ASSEMBLER; REGISTER;
  ASM
     XCHG   DX,AX
     OUT    DX,AL
  END;

////////////////////////////////////////////////////////////////////////////

  FUNCTION B2X(CONST b:  BYTE):  STRING;  {byte-to-hexadecimal}
    CONST HexDigit:  ARRAY[0..15] OF CHAR = '0123456789ABCDEF';
  BEGIN
    RESULT :=  HexDigit[b SHR 4] + HexDigit[b AND $0F]
  END {B2X};


  FUNCTION C2X(CONST s:  STRING):  STRING;  {character-to-hexadecimal}
    VAR
      i:  BYTE;
      t:  STRING;
  BEGIN
    t := '';
    FOR i := 1 TO LENGTH(s) DO
    BEGIN
      AppendStr(t, B2X( BYTE(s[i]) ));
    END;
    RESULT := t
  END {C2X};


  PROCEDURE TForm1.CMOSsummary;
    VAR
      i,j,k:  BYTE;
      line :  STRING[16];
      hex  :  STRING[32];
  BEGIN
    Memo1.Lines.Add('CMOS RAM Memory');
    Memo1.Lines.Add ('   . . . . | . . . . | . . . . | .
..|....|....|.');
    k := 0;
    FOR j := 1 TO 4 DO BEGIN
      line := '';
      FOR i := 1 TO 16 DO BEGIN
        PORTOut($70,k);
        line := line + CHR(PORTIn($71));
        INC (k);
      END;
      hex := C2X(line);
      FOR i := 1 TO 16 DO
        IF   NOT (line[i] IN [#$20..#$7E])
        THEN line[i] := '.';           {an 'unprintable' character}
      Memo1.Lines.Add ('  ' + hex + '  ' + line)
    END
  END;


procedure TForm1.ButtonCMOSInfoClick(Sender: TObject);
begin
  CMOSSummary
end;


FUNCTION BCDToInt(bcd:  BYTE):  INTEGER;
BEGIN
  RESULT := 10*(bcd SHR 4) + (bcd AND $0F)
END;


FUNCTION IntToBCD(i:  INTEGER):  BYTE;
BEGIN
  RESULT := 16*(i DIV 10) + (i MOD 10)
END;



// See IBM ROM BIOS by Ray Duncan, Microsoft Press, 1988
PROCEDURE GetCMOSDate(VAR Day, Month, Year, Century:  BYTE);  PASCAL;
BEGIN
  // All values returned are BCD -- binary-coded decimal
  asm
    MOV AH,$04
    INT $1A        // BIOS Call:  Read date from real-time clock

    MOV EAX,Century
    MOV [EAX],CH

    MOV EAX,Year
    MOV [EAX],CL

    MOV EAX,Month
    MOV [EAX],DH

    MOV EAX,Day
    MOV [EAX],DL
  end;

  // Convert from BCD to binary
  Century := BCDToInt(Century);
  Year := BCDToInt(Year);
  Month := BCDToInt(Month);
  Day := BCDTOInt(Day)
END;


PROCEDURE SetCMOSDate(Day, Month, Year, Century:  BYTE);  PASCAL;
  VAR
    BCDDay    :  BYTE;
    BCDMonth  :  BYTE;
    BCDYear   :  BYTE;
    BCDCentury:  BYTE;
BEGIN
  BCDDay := IntToBCD(Day);
  BCDMonth := IntToBCD(Month);
  BCDYear := IntToBCD(Year);
  BCDCentury := IntToBCD(Century);

  asm
    MOV AH,$05
    MOV CH,BCDCentury
    MOV CL,BCDYear
    MOV DH,BCDMonth
    MOV DL,BCDDay
    INT $1A        // BIOS Call:  Set real-time clock date
  end
END;


PROCEDURE GetCMOSTime(VAR Hours, Minutes, Seconds, SavingsTime:  BYTE);
PASCAL;
BEGIN
  // All values returned are BCD -- binary-coded decimal
  asm
    MOV AH,$02
    INT $1A        // BIOS Call:  Read

    MOV EAX,Hours
    MOV [EAX],CH

    MOV EAX,Minutes
    MOV [EAX],CL

    MOV EAX,Seconds
    MOV [EAX],DH

    MOV EAX,SavingsTime
    MOV [EAX],DL
  end;

  Hours := BCDToInt(Hours);
  Minutes := BCDToInt(Minutes);
  Seconds := BCDToInt(Seconds);
  SavingsTime := BCDToInt(SavingsTime);
END;


PROCEDURE SetCMOSTime(Hours, Minutes, Seconds, SavingsTime:  BYTE);  PASCAL;
  VAR
    BCDHours      :  BYTE;
    BCDMinutes    :  BYTE;
    BCDSeconds    :  BYTE;
    BCDSavingsTime:  BYTE;
BEGIN
  BCDHours := IntToBCD(Hours);
  BCDMinutes := IntToBCD(Minutes);
  BCDSeconds := IntToBCD(Seconds);
  BCDSavingsTime := IntToBCD(SavingsTime);

  asm
    MOV AH,$03
    MOV CH,BCDHours
    MOV CL,BCDMinutes
    MOV DH,BCDSeconds
    MOV DL,BCDSavingsTime
    INT $1A        // BIOS Call:  Set real-time clock time
  end
END;


procedure TForm1.ButtonReadClockClick(Sender: TObject);
  VAR
    Century    :  BYTE;
    Day        :  BYTE;
    Hours      :  BYTE;
    Minutes    :  BYTE;
    Month      :  BYTE;
    SavingsTime:  BYTE;
    Seconds    :  BYTE;
    year       :  BYTE;
begin
  GetCMOSDate(Day, Month, Year, Century);
  GetCMOSTime(Hours, Minutes, Seconds, SavingsTime);

  Memo1.Lines.Add(
    IntToStr(Month) + '/' +
    IntToStr(Day) + '/' +
    IntToStr(100*Century + Year ) + '  ' +

    IntToStr(Hours) + ':' +
    IntToStr(Minutes) + ':' +
    IntToStr(Seconds) + '  Savings=' +
    IntToStr(SavingsTime));
end;

procedure TForm1.ButtonSetClockClick(Sender: TObject);
begin
  SetCMOSDate(SpinEditDay.Value,
              SpinEditMonth.Value,
              SpinEditYear.Value,
              SpinEditCentury.Value);

  SetCMOSTime(SpinEditHours.Value,
              SpinEditMinutes.Value,
              SpinEditSeconds.Value,
              0 {for savings time for now});  // use 1 for savings time
end;

end.

THANKS!

Keep in touch ,
Nick
nick@decebal.ro