How to read Hard Disk Serial No. ( Volume No.) in C++ program ?

Posted on 1998-04-22
Last Modified: 2008-02-01
I want to implement a functionality in my C/C++ program to read the hard disk serial no. ( Volume no. ) on which it is installed. Every time it runs , i want to check the serial no. to validate it...Can somebody suggest me a way for doing this ??
If someone can give me the function which does that i would really appreciate!!! Or suggest me the elegant way of achieving the same...
Hope to hear soon....
Question by:nikhil_vora
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
  • 5
  • 2
LVL 22

Accepted Solution

nietod earned 200 total points
ID: 1163226
LVL 22

Expert Comment

ID: 1163227
Use the GetVolumeInformation() Windows API procedure.  With this procedure you specify a path to the root directory of the volumne you are interested in, like "C:\\"  (two backslashes specified to put one in the string).  The procedure returns a bunch of different pieces of information one of which is the serial number.  

Let me know if you need more.

Author Comment

ID: 1163228
This gives me the volume no. of drive of the hard disk, here what happens is that if i hv 3 drives on my hard disk named c,d,e i will hv 3 different volume no. for same hard disk, can i hv the serial no. of the hard disk itself ??
Also, what i am not sure is that whether this serial no.s on the drive are unique or not ??? I think ,  i can hv duplicate volume serial no. ( correct me if i am wrong )!!!!
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!

LVL 22

Expert Comment

ID: 1163229
I have no earthly idea.  I can test it though.
LVL 22

Expert Comment

ID: 1163230
Apparently this functon returns the "volume serial number" which is not the same as the "hard disk serial number".  If you have a single disk that is partitioned into two or more volumes, each volume has its own volume serial number.  Is that a problem?
LVL 11

Expert Comment

ID: 1163231
Volume serial numbers are not guaranteed to be unique.  They are pseudo-random numbers that have a GOOD CHANCE of being unique, not more than that.
If you want something that is guaranteed to be unique, use the network card's MAC number.  Problem is, the computer might not have a network card...
LVL 22

Expert Comment

ID: 1163232
If I had to guess (and I do have to guess) this is probably for a software copy protection system.  If so, the volumne serial numbers are unique enough.  It means that the users would be able to copy the software and make it run on another computer that has the same volumne number.  But the odds of two volumes having the same number are 1 in 4 billion.  That seems adequate.  

Author Comment

ID: 1163233
Does anybody know abt. any other unique identity on PC which i can use instead of hard disk volume no. ? I think i can use bios check sum for this validation also ? Can anybody suggest me something ?
I don't want to use MAC serial no. as the PC may not be having it. But i think getting bios info. should be ok, can somebody throw some light on how to get it ?? Also, if anybody has some good suggestion abt. the scheme , please let me know.


Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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
Cross compile release version of c++ program for linux 2 146
mixing C++ & C# in Vis Studio 2013 7 280
FMX StringGrid1->Canvas->FillRect Problem 3 221
Gaming Software 1 38
Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

738 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