Solved

How can I get the Hard disk serial number

Posted on 1998-08-10
2
660 Views
1 Endorsement
Last Modified: 2010-04-03
I want to get the hard disk serial number also cd-rom serial number
1
Comment
Question by:Motaz
2 Comments
 
LVL 8

Accepted Solution

by:
ZifNab earned 70 total points
ID: 1361813
to get serial numer of cd :

{ps : look also at my freeware component CDEvents.}

function TCDEvents.GetCDInfo(vWord:Word):String;
       var msp : TMCI_INFO_PARMS;
           MediaString : array[0..255] of char;
           ret : longint;
       begin
        FillChar(MediaString, SizeOf(MediaString), #0);
        FillChar(msp, sizeof(msp), #0);
        msp.lpstrReturn := @MediaString;
        msp.dwRetSize := 255;
        ret := mciSendCommand(ID,
                              MCI_INFO,
                              vWord,
                              longint(@msp));
        if Ret <> 0 then begin
          MciGetErrorString(ret, @MediaString, SizeOf(MediaString));
          Result := StrPas(MediaString);
        end else Result := StrPas(MediaString);
       end;

       function TCDEvents.GetSerialNumber: string;
       begin
        Result := GetCDInfo(MCI_INFO_MEDIA_IDENTITY);
       end;

For disk :

You can use the Windows API function GetVolumeInformation()

  procedure TForm1.Button1Click(Sender: TObject);
     var
      VolumeSerialNumber : DWORD;
      MaximumComponentLength : DWORD;
      FileSystemFlags : DWORD;
      SerialNumber : string;
    begin
     GetVolumeInformation('C:\',
                          nil,
                          0,
                          @VolumeSerialNumber,
                          MaximumComponentLength,
                          FileSystemFlags,
                          nil,
                          0);
   SerialNumber := IntToHex(HiWord(VolumeSerialNumber), 4) +
                  '-' +                                                                            IntToHex(LoWord(VolumeSerialNumber), 4);
    Memo1.Lines.Add(SerialNumber);
 end;

Zif.

0
 

Expert Comment

by:albilgin
ID: 2041562
Hi Motaz
here is the function , it is simple
-----------------------------------------------

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;

A call example:
       Label1.Caption:=GetVolumeId('c');

-----------------------------------------------
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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 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…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

920 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

13 Experts available now in Live!

Get 1:1 Help Now