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.



Sabbir456Asked:
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:
http://java.sun.com/javase/6/docs/api/java/net/NetworkInterface.html#getHardwareAddress()

If you're pre-Java 6 then you might try the code here:
http://thecodersblog.blogspot.com/2007/06/java-getting-mac-addresses-of-network.html
0
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.

0
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:
Right.
Well here's the code you asked for:


import java.io.*;
 
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) {
                count++;
                if (count<2)
                    continue;
                if (count>2)
                    break;
                return line.substring( line.lastIndexOf(' ')+1 );
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

Open in new window

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

Open in new window

0
zzynxSoftware engineerCommented:
Well, after the try/catch

you'll need a extra instruction

   return "?";

to make it compile

;°)
0

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 ..
0
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
0
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
Java

From novice to tech pro — start learning today.