Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

HDD serial number

Posted on 2001-08-17
5
325 Views
Last Modified: 2012-05-04
How do I obtain the serial number of the PC's hard disk, or any other number/string which is unique to that particlar machine?
0
Comment
Question by:nuttyprofessor
  • 4
5 Comments
 
LVL 3

Expert Comment

by:VSF
ID: 6396755
Function GetDiskSerialNumber(DriveLatter:String) : DWord;
      Var
        a,b : Integer;
        buffer : array[0..255] of char;
        B1 : PChar;
        SerialNumber : Dword;
      Begin
        New(B1);
        B1 := StrPCopy(B1, DriveLatter + ':\');
        GetVolumeInformation(B1, Buffer,
sizeof(buffer),@SerialNumber,a,b,nil,0);
        Result := SerialNumber;
        Dispose(B1);
      End;


This should do it!

VSF
www.victory.hpg.com.br
0
 
LVL 3

Expert Comment

by:VSF
ID: 6396801
You can also use some BIOS information as unique keys!
To get the BIOS info use one of the following functions:

//FUNCTION TO GET COMPLETE BIOS INFO AS TEXT
function GetBiosInfoAsText: string;
  var
    p, q: pchar;
  begin
    q := nil;
    p := PChar(Ptr($FE000));
    repeat
      if q <> nil then begin
        if not (p^ in [#10, #13, ' '..'~' , '?' , '?' ]) then begin
          if (p^ = #0) and (p - q >= 8) then begin
            Result := Result + TrimRight(String(q)) + #13#10;
        end;
          q := nil;
        end;
      end else
         if p^ in ['!'..'~' , '?' , '?' ] then
          q := p;
      inc(p);
    until p > PChar(Ptr($FFFFF));
    Result := TrimRight(Result);
  end;

procedure TForm1.Button1Click(Sender: TObject);
begin
memo1.Lines.text:=GetBiosInfoAsText;
end;


//SIMPLE CODE TO GET ONLY THE BIOS DATE
procedure TForm1.Button1Click(Sender: TObject);
begin
edit1.text:=String(PChar(Ptr($FFFF5)));
end;



Hope this helps!
VSF
www.victory.hpg.com.br
0
 
LVL 3

Accepted Solution

by:
VSF earned 50 total points
ID: 6396824
Here is a more complete and easy to use function to get HDD serial number:

function GetVolumeID(DriveChar: Char): String;
 var
   MaxFileNameLength, VolFlags, SerNum: DWord;
 begin
   if GetVolumeInformation(PChar(DriveChar + ':\'), nil, 0,
      @SerNum, MaxFileNameLength, VolFlags, nil, 0)
   then
   begin
     Result := IntToHex(SerNum,8);
     Insert('-', Result, 5);
   end
   else
    Result := '';
 end;

procedure TForm1.Button1Click(Sender: TObject);
begin
 edit1.text:=GetVolumeID(extractfilepath(application.exename)[1]);    //This will return the drive where the program is runnig into (Note: it may not be the C drive!)
end;


This should do it!
VSF
www.victory.hpg.com.br
0
 
LVL 22

Expert Comment

by:Mohammed Nasman
ID: 6396830
Hello

  This is the Volume serial for partition "c", no not the hard diks serial number, so every time you format this partition it will change, even there are some utilities could change the Volume number, or you can change it also from code, so this way it will not be good if you want to do that for software protection

look at this link for
Getting the BIOS serial number
http://www.latiumsoftware.com/en/delphi/00050.php3

Best regards
Mohammed Nasman



0
 
LVL 3

Expert Comment

by:VSF
ID: 6398346
I'm glad to help!
Please show your support visiting my homepage!

www.victory.hpg.com.br
www.enge.cjb.net 

VSF
UIN:14016999
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Delphi XE10 Round Image 2 154
Delphi Form ownership 4 110
Performance of SQL statement 37 127
how to update exe applicatio from internet ? 6 86
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question