Solved

HDD serial number

Posted on 2001-08-17
5
332 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
[X]
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
  • 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses
Course of the Month10 days, 3 hours left to enroll

623 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