Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 754
  • Last Modified:

How can I get the Hard disk serial number

I want to get the hard disk serial number also cd-rom serial number
1
Motaz
Asked:
Motaz
1 Solution
 
ZifNabCommented:
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
 
albilginCommented:
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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now