Link to home
Start Free TrialLog in
Avatar of BujorCristinel
BujorCristinel

asked on

HDD physical serial number

Extract physical serial number for HDD (IDE, RAID IDE, SCSI, RAID SCSI) in Windows 98, ME, NT, 2000 or XP.
Avatar of Amir Azhdari
Amir Azhdari
Flag of United States of America image

listening
Avatar of Karitz
Karitz


Type
 ArraySTR = Array[0..255] Of Byte;
Const
 WhichDrv: Array[1..2] Of Word = ($A0,$B0);
Var
 NumDrv: Word Absolute $0040:$0075; { BIOS info on how many HDD you have }
 Regs: Registers;
 Data: ArraySTR;
 DataOff: Byte;
 Loop: Integer;

Function GetString(InData: ArraySTR; OffStart,OffEnd: Byte): String;
Var
 TempSTR: String;
 I: Byte;
Begin
 TempSTR:='';
 For I:=OffStart To OffEnd Do
   TempSTR:=TempSTR+Char(InData[I]);
 GetString:=TempSTR;
End;

Begin
 ClrScr;
 WriteLn('You have ',NumDrv,' Hard Disk(s).');
 For Loop:=1 to NumDrv Do
   Begin
     WriteLn('  Info on Hard Disk ',NumDrv,' is:');
     While Port[$01F7] <> $50 Do; { Wait For controller not busy }
     Port[$01F6]:=WhichDrv[Loop]; { Get first/second drive }
     Port[$01F7]:=$EC;            { Get drive info data }
     While Port[$01F7] <> $58 Do; { Wait for data ready }
     For DataOff:=0 To 255 Do     { Read "sector" }
       Data[DataOff]:=Port[$01F0];
     WriteLn('    Model Number: ',GetString(Data,27,46));
     WriteLn('    Serial Number: ',GetString(Data,10,19));
   End;
End.


https://www.experts-exchange.com/questions/10351427/READ-HARD-DISK-SERIAL-NUMBER.html
ASKER CERTIFIED SOLUTION
Avatar of geobul
geobul

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
Use the GetSerialNumber function below:

Function GetSerialNumber: string;
var
  VolSerNumber : DWORD;
  MaxFilenameLength : DWORD; //system's maximum filename length
  FSFlags : DWORD; //file system flags

begin
  GetVolumeInformation('C:\', nil, 0, @VolSerNumber,
MaxFilenameLength, FSFlags, nil, 0);
  Result := IntToHex(HiWord(VolSerNumber), 4)+'-'+IntToHex(LoWord(VolSerNumber), 4);
end;

You will need 'windows' in your uses clause as GetVolumeInformation is windows API call.

Hope this helps.

Regards
Pierre
PierreC, That's the Volume No, not the physical No, for example check each parition you will find each one has a volume no, but the whole HD has only one physical serial no
Thanks for the correction...
Try this :-0

function GetHardDiskSerial(const DriveLetter: Char): string;
var
  NotUsed:     DWORD;
  VolumeFlags: DWORD;
  VolumeInfo:  array[0..MAX_PATH] of Char;
  VolumeSerialNumber: DWORD;
begin
  GetVolumeInformation(PChar(DriveLetter + ':\'),
    nil, SizeOf(VolumeInfo), @VolumeSerialNumber, NotUsed,
    VolumeFlags, nil, 0);
  Result := Format('Label = %s   VolSer = %8.8X',
    [VolumeInfo, VolumeSerialNumber])
end;


procedure TForm1.Button1Click(Sender: TObject);
begin
  ShowMessage(GetHardDiskSerial('c'));
end;

Hope this will help

BujorCristinel:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
geobul should get the points, I would say, reduce to 200pts and award him an A... just my 2cents :)
Hi!
No comment has been added lately and this question is therefore classified abandoned.

If asker wishes to close the question, then refer to
https://www.experts-exchange.com/help/closing.jsp

Otherwise, I will leave a recommendation in the Cleanup topic area that this question is:

Answered by:  geobul

Please leave any comments here within the next seven days. It is assumed that any participant not responding to this request is no longer interested in its final disposition.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

...Snehanshu
EE Cleanup Volunteer