Solved

How can I get the Hard disk serial number

Posted on 1998-08-10
2
680 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Machine not responding during CopyFile() 3 103
Simple Delphi Question 9 96
Comparing dates in Delphi. Greater than/ Less than 3 211
Making delphi communicate with a c# service 16 111
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
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…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

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