Solved

getting Volume serial number

Posted on 2001-09-04
9
344 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
Comment Utility
Use GetVolumeInformation function
0
 
LVL 5

Accepted Solution

by:
alanwhincup earned 50 total points
Comment Utility
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
Comment Utility
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
 

Author Comment

by:hutelihut
Comment Utility
Is'nt it true, that GetVolumeInformation only works on harddrives???
(im not sure..)
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

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

Expert Comment

by:VSF
Comment Utility
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
Comment Utility
Okey, who should now have the points?
0
 
LVL 3

Expert Comment

by:VSF
Comment Utility
It's up to you to decide which solution fits better!

VSF
www.victory.hpg.com.br
0
 

Author Comment

by:hutelihut
Comment Utility
Alanwhincup was the first one who mentioned GetVolumeInformation
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

763 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now