Solved

getting Volume serial number

Posted on 2001-09-04
9
356 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…

717 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