Solved

How can I get the Hard disk serial number

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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Simple Delphi Question 9 89
add combobox item based on numbers 9 141
how to center only a line in richedit? 4 57
Dynamically Created Query 3 55
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

770 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