Solved

HDD serial number

Posted on 2001-08-17
5
318 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:mnasman
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

746 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now