Solved

HDD serial number

Posted on 2001-08-17
5
327 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

756 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