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?
zzynxConnect With a Mentor Software engineerCommented:
Well, after the try/catch

you'll need a extra instruction

   return "?";

to make it compile

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:
Never miss a deadline with

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

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.

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

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
All Courses

From novice to tech pro — start learning today.