Solved

getting Volume serial number

Posted on 2001-09-04
9
352 Views
Last Modified: 2010-04-06
How do I get the volume serial number from any kind of drive (ex. floppydisk or harddrive)?
0
Comment
Question by:hutelihut
9 Comments
 
LVL 3

Expert Comment

by:Slavak
ID: 6453570
Use GetVolumeInformation function
0
 
LVL 5

Accepted Solution

by:
alanwhincup earned 50 total points
ID: 6453623
Here is an example. To use it just stick a DriveComboBox and a Label on a form and put the below code into the DriveComboBox's OnChange event:

procedure TForm1.DriveComboBox1Change(Sender: TObject);
var
  Drive, Name : array[0..255] of Char;
  SerialNum, CompLength, Flags : DWord;
begin
  StrPCopy(Drive, DriveComboBox1.Drive + ':\');
  if (GetVolumeInformation(Drive, Name, 256, @SerialNum, CompLength, Flags, nil, 256)) then
  begin
    Label1.Caption := IntToHex(SerialNum shr 16, 4) + '-' + IntToHex((SerialNum shl 16) shr 16, 4);
  end
  else
    Label1.Caption := 'Error...';
end;

Cheers,

Alan
0
 
LVL 3

Expert Comment

by:VSF
ID: 6458104
NuttyProfessor Graded me with an A on this link for this above answer
http://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(extractfilepath(application.exename)[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 
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

Author Comment

by:hutelihut
ID: 6479091
Is'nt it true, that GetVolumeInformation only works on harddrives???
(im not sure..)
0
 

Author Comment

by:hutelihut
ID: 6479095
(ohh bad gramma, I think - hope you will understand)
0
 
LVL 3

Expert Comment

by:VSF
ID: 6479221
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:=GetVolumeID(edit1.text[1]); //Type A in the edit1 and it will work for sure!
end;
0
 

Author Comment

by:hutelihut
ID: 6482460
Okey, who should now have the points?
0
 
LVL 3

Expert Comment

by:VSF
ID: 6482822
It's up to you to decide which solution fits better!

VSF
www.victory.hpg.com.br
0
 

Author Comment

by:hutelihut
ID: 6489980
Alanwhincup was the first one who mentioned GetVolumeInformation
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

803 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