how te get volume serial number in java ?

I need to get the volume serial number using java. Code example will be very useful.

 Objective is to use this information to lock a particular java program for a particular PC only.

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

zzynxSoftware engineerCommented:
>> Objective is to use this information to lock a particular java program for a particular PC only.

One common way to uniquely (or as close to uniquely as possible) identify a computer using Java,
is to get the MAC address of the network adapter. That's usually sufficient.
If you're using Java 6 then you can use the NetworkInterface class for that:

If you're pre-Java 6 then you might try the code here:
Sabbir456Author Commented:
hi zzynx,
Yes we are using java 6 and was thinking like wise to use MAC Address .. but the target customers (schools) of the solution mostly have single PC (without any network interface), that's why we are looking for an alternative like HDD serial or any other unique system indentifier. thanks.

Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

zzynxSoftware engineerCommented:
Well here's the code you asked for:

public class GetVolumeSerialNumberDemo {
    public static void main(String args[]) {
        System.out.println("Volume Serial ID = <" + getVolumeSerialId() + ">");
    private static String getVolumeSerialId() {
        try {
            Process p = Runtime.getRuntime().exec("cmd /C dir");
            BufferedReader in = new BufferedReader(
                                new InputStreamReader(p.getInputStream()));
            String line = null;
            int count = 0;
            while ((line = in.readLine()) != null) {
                if (count<2)
                if (count>2)
                return line.substring( line.lastIndexOf(' ')+1 );
        } catch (IOException e) {

Open in new window

zzynxSoftware engineerCommented:
This gives me as output:
Volume Serial ID = <F4F2-EFC8>

Open in new window

zzynxSoftware engineerCommented:
Well, after the try/catch

you'll need a extra instruction

   return "?";

to make it compile


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Sabbir456Author Commented:
Hi, Thanks a lot. Solution worked just fine, Though we have found that volume serial number can be changed and user can cnange the volume serial to run unliscensed copy. We will actually need the manufacturer serial no of HDD, but may be that is not possible only with java ..
zzynxSoftware engineerCommented:
thanx 4 axxepting

>> We will actually need the manufacturer serial no of HDD
Then you'll probably need to use some 3rd party library
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.