hutelihut
asked on
getting Volume serial number
How do I get the volume serial number from any kind of drive (ex. floppydisk or harddrive)?
Use GetVolumeInformation function
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
NuttyProfessor Graded me with an A on this link for this above answer
https://www.experts-exchange.com/jsp/qShow.jsp?ta=delphi&qid=20170016
Here is complete and easy to use function to get HDD serial number:
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;
procedure TForm1.Button1Click(Sender : TObject);
begin
edit1.text:=GetVolumeID(ex tractfilep ath(applic ation.exen ame)[1]); //This will return the drive where
the program is runnig into (Note: it may not be the C drive!)
end;
This should do it!
VSF
www.victory.hpg.com.br
https://www.experts-exchange.com/jsp/qShow.jsp?ta=delphi&qid=20170016
Here is complete and easy to use function to get HDD serial number:
function GetVolumeID(DriveChar: Char): String;
var
MaxFileNameLength, VolFlags, SerNum: DWord;
begin
if GetVolumeInformation(PChar
@SerNum, MaxFileNameLength, VolFlags, nil, 0)
then
begin
Result := IntToHex(SerNum,8);
Insert('-', Result, 5);
end
else
Result := '';
end;
procedure TForm1.Button1Click(Sender
begin
edit1.text:=GetVolumeID(ex
the program is runnig into (Note: it may not be the C drive!)
end;
This should do it!
VSF
www.victory.hpg.com.br
ASKER
Is'nt it true, that GetVolumeInformation only works on harddrives???
(im not sure..)
(im not sure..)
ASKER
(ohh bad gramma, I think - hope you will understand)
No!
It's not true!
I just tested it on my machine using Delphi 5 and Windows 98 and it worked perfectly for my floppy disk!
Take a better look at the code!
Trust me.... it works!
VSF
www.victory.hpg.com.br
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;
procedure TForm1.Button1Click(Sender : TObject);
begin
button1.caption:=GetVolume ID(edit1.t ext[1]); //Type A in the edit1 and it will work for sure!
end;
It's not true!
I just tested it on my machine using Delphi 5 and Windows 98 and it worked perfectly for my floppy disk!
Take a better look at the code!
Trust me.... it works!
VSF
www.victory.hpg.com.br
function GetVolumeID(DriveChar: Char): String;
var
MaxFileNameLength, VolFlags, SerNum: DWord;
begin
if GetVolumeInformation(PChar
@SerNum, MaxFileNameLength, VolFlags, nil, 0)
then
begin
Result := IntToHex(SerNum,8);
Insert('-', Result, 5);
end
else
Result := '';
end;
procedure TForm1.Button1Click(Sender
begin
button1.caption:=GetVolume
end;
ASKER
Okey, who should now have the points?
ASKER
Alanwhincup was the first one who mentioned GetVolumeInformation