Solved

getting Volume serial number

Posted on 2001-09-04
9
354 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
Industry Leaders: 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Press three keys together and trigger a function 3 67
SUM 2 INTEGER ARRAYS INTO 1 10 111
Microsoft Access 97 and Delphi XE2 9 71
Using MMsystem To change audio input 1 14
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
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…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

685 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