Solved

HDD serial number

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

ScreenConnect 6.0 Free Trial

Check out the updates in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI that improves session organization and overall user experience. See the enhancements for yourself!

Question has a verified solution.

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

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …

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