Procedure ShowDriveSerialNo(Drive : String); // Drive as 'c:' or 'd:', ...
var VolSerNum: DWORD;
    Dummy1, Dummy2: DWORD; 
begin 
  if GetVolumeInformation(drive+'\', NIL, 0, @VolSerNum, Dummy1, Dummy2, NIL, 0) then ShowMessage(Format('%.4x:%.4x', [HiWord(VolSerNum), LoWord(VolSerNum)]));
End;

Function GetDriveSerialNo(Drive : String) : String; // Drive as 'x:' ...
var VolSerNum: DWORD;
    Dummy1, Dummy2: DWORD; 
begin 
  if GetVolumeInformation(drive+'\', NIL, 0, @VolSerNum, Dummy1, Dummy2, NIL, 0) then Result := Format('%.4x:%.4x', [HiWord(VolSerNum), LoWord(VolSerNum)]);
End;
5
Contributors
5
Replies
6
Views
10 Years
Discussion Span
Last Post by hingman
0

Sounds nice, but I don't understand the difference between
Drive as 'c:'
and
Drive as x:'

Please explain.

Arne

-1

Hi AKJo,

And what about you LEARN programming?

Computers are machines that are useful not only for GAMES, MUSIC and VIDEOS, but also for USEFUL TASKS.

Edited by 123ofOliveTree4: n/a

Votes + Comments
Nothing in this post adds any knowledge
0

Thank you 123ofOliveTree4 for your good advice. It made me look closer to the code and discovered that the difference in drives were not the importent difference between line 1-6 and 8-13, but the first one describes "Show" and the second part describes "Get". I didn't discover that before, but only saw the different drives.

Thanks again 123ofOliveTree4 for your good advice. I have only tried learning programming since 1968. Obviously I have failed. It would be nice if you are kind to teach me some.

1

The next code works for all HDD Volumes in my Computer:

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Memo1: TMemo;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}


function GetVolumeID(DriveChar: Char): string;
var
 MaxFileNameLength, VolFlags, SerNum: DWord;
begin
  if GetVolumeInformation(PAnsiChar(DriveChar + ':\'), nil, 0, @SerNum, MaxFileNameLength, VolFlags, nil, 0)
  then
  begin
    Result := IntToHex(SerNum,8);
    Insert('-', Result, 5);
  end
  else
    Result := '';
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  C:      Char;
  S:      string;
begin
  Memo1.Lines.Clear;
  for C := 'C' to 'Z' do
  begin
    begin
      S := GetVolumeID(C);
      Memo1.Lines.Add(S);
    end;
  end;
end;

end.

()

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Memo1: TMemo;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}


function GetVolumeID(DriveChar: Char): string;
var
 MaxFileNameLength, VolFlags, SerNum: DWord;
begin
  if GetVolumeInformation(PAnsiChar(DriveChar + ':\'), nil, 0, @SerNum, MaxFileNameLength, VolFlags, nil, 0)
  then
  begin
    Result := IntToHex(SerNum,8);
    Insert('-', Result, 5);
  end
  else
    Result := '';
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  C:      Char;
  S:      string;
begin
  for C := 'C' to 'Z' do
  begin
    begin
      S := GetVolumeID(C);
      Memo1.Lines.Add(S);
    end;
  end;
end;

end.

Edited by mike_2000_17: Fixed formatting

0

I use GetDiskSerial DLL in my product.

This dll file can read the unique serial number of hard disk In your windows application.

Good luck :-)

Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.