Solved

How can I get the Hard disk serial number

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

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