Jump to content

Recommended Posts

I'm building a Licensing application, and was trying to figure out a way to programmatically read the Hard Drive serial number (not the Volume number, the actual static physical serial number) to use as a license key. Does anyone have any ideas on how to do this in Windows and/or Linux? (If you can do it in another programming language, that would be ok too, but LV is preferred).

Thanks in advance

Link to comment

In did this a long time ago like this (only for windows).

Make a system call to "Dir nothing.txt" this will give you this result:

H:\>dir nothing.txt Volume in drive H is Data Volume Serial Number is [color="#ff0000"]64BA-5E87[/color] Directory of H:\File Not FoundH:\>

Then just parse the string

//Mikael

  • Like 1
Link to comment

In did this a long time ago like this (only for windows).

Make a system call to "Dir nothing.txt" this will give you this result:

H:\>dir nothing.txt Volume in drive H is Data Volume Serial Number is [color="#ff0000"]64BA-5E87[/color] Directory of H:\File Not FoundH:\>

Then just parse the string

//Mikael

This method may be simply hooked by creating read-only file nothing.txt where you can put whatever you want. Of course one has to figure out first what and where to create... Anyway, much safer method is GetVolumeInformation function from kernel32.dll (to be used with Call Library Function Node).

Link to comment
This method may be simply hooked by creating read-only file nothing.txt where you can put whatever you want. Of course one has to figure out first what and where to create...

You don't need to create anything - that's why Mike's example returned "File Not Found".

Anyway, much safer method is GetVolumeInformation function from kernel32.dll (to be used with Call Library Function Node).

I'm not sure if that's safer or not, but I agree - I'd prefer to use the GetVolumneInformation function as well.

Link to comment

You don't need to create anything - that's why Mike's example returned "File Not Found".

:frusty: It's 1.30 AM - I would better go sleep...

[edit]

but string parser should be OS language independent

Edited by vugie
Link to comment
frusty.gif It's 1.30 AM - I would better go sleep...

:D

but string parser should be OS language independent

I don't know other OSes, but I think you'd need to call the command lines differently at least, and I figure they'd all return the information in different ways. Anyone with multiple OS experience care to comment?

Link to comment

I was actually hoping to avoid using the Volume Serial Number, since I understand that it is not very static (reformatting will change it, and make the license obsolete). I was leaning more towards a physical Serial Number of the hard drive which can only be changed if the hard drive is swapped. MAC Address is no good since disabling the network card will make it impossible to read, and internet is not necessary to run the program.

Michael's link fruited some ideas about using the BIOS card, which I'm looking into now. Any ideas about this?

Link to comment

What happens if the disk crashes? IT happens. Have you considered using a dongle instead? They're cheap and very easy to implement.

We want the user to be able to run the program on any computer once he has paid for the program, simultaneously and at no extra charge.

Also, our program is going to be released piggy backed on another program, so the user may buy the main program with no intention of using ours. In the interest of time, we do not want to have the user to wait for a dongle to arrive if they do want to activate our program.

It's an easy fix to give the user a new license key if their hard drive crashes, they would just need to repeat the activation process but would not have to pay again.

Link to comment

I was actually hoping to avoid using the Volume Serial Number, since I understand that it is not very static (reformatting will change it, and make the license obsolete). I was leaning more towards a physical Serial Number of the hard drive which can only be changed if the hard drive is swapped. MAC Address is no good since disabling the network card will make it impossible to read, and internet is not necessary to run the program.

Michael's link fruited some ideas about using the BIOS card, which I'm looking into now. Any ideas about this?

As for volume physical serial number you may use Win32_PhysicalMedia class from Windows Management Instrumentation, but you would have to build your own DLL wrapper in C++ or use MS script engine to get this information (examples for both methods for WMI are provided in above link). Additionally WMI gives you classes (I may be wrong - just found this out) to get virtually any number from hardware (i.e. motherboard serial). But it seems to be little bit tricky to use and works only for XP and above.

Alternatively you may use diskid32 freeware tool in manner similar to "dir nothing".

Using MAC address for licensing is a joke as changing it is very simple even for not advanced user. IMO optimal way is to use combination of few hardware related serials and obsoleting license only when ALL of them change.

Link to comment
  • 3 weeks later...

Is this a .Net DLL or something? 508kB for these few functions seems a bit excessive to me. Or is that the price one has to pay nowadays for using VC 2008? :wacko:

Rolf Kalbermatter

No its a Delphi DLL. It can actually do more than just those 2 functions, but this thread was asking for serial numbers.

Saying that though...... Getting the info is far from trivial.

Edited by ShaunR
Link to comment

Is this a .Net DLL or something? 508kB for these few functions seems a bit excessive to me. Or is that the price one has to pay nowadays for using VC 2008? :wacko:

Rolf Kalbermatter

Thinking about what you said. It did seem a little large even with the extra functions. So I went back and took a look (on a weekend too :P )and realised a unit was included that wasn't necessary (used during debugging). Well spotted!

I

Is 162KB more to your liking?

Edited by ShaunR
Link to comment

No its a Delphi DLL. It can actually do more than just those 2 functions, but this thread was asking for serial numbers.

Saying that though...... Getting the info is far from trivial.

Yes, I know. Especially since most methods to get this information, including the one used here, are hampered with limitations about who can retrieve the information. You do need admin or elevated rights to run this IOCTL code.

Thinkingabout what you said. It did seem a little large even with the extrafunctions. So I went back and took a look (on a weekend too :P )and realised a unit was included that wasn't necessary (used during debugging). Well spotted!

I

Is 162KB more to your liking?

It is better but I get that in my own lvUtil DLL, which does a lot of other things too, such as printing of LabVIEW strings to any Windows printer, serial port enumeration, pipe implementation and a few other things like network MAC and CPUID retrieval in about 32kB :P.

GetDiskInfo!!! It doesn't work in my system.

My system:

Dell 330,

WinXP Sp3

Labview 8.6.1f1

VS2008 SP1

I have another VI named "Get hard disk volume info" work well in my system.

Are you running it with admin rights? In Vista it even most probably needs to run with elevated rights independent if you are logged in a administrator or not. The used IOCTL code seems to be not accessible without admin rights and in the case of Vista it seems to even require explicit elevation.

Get Harddisk Volume Info, returns the serial number of the formatted volume which is a random (or not so random, because format allows to specify what volume serial number should be used) number assigned to the partition during formatting.

Rolf Kalbermatter

Link to comment

Yes, I know. Especially since most methods to get this information, including the one used here, are hampered with limitations about who can retrieve the information. You do need admin or elevated rights to run this IOCTL code.

Then why ask if ists a .NET dll :unsure:

It is better but I get that in my own lvUtil DLL, which does a lot of other things too, such as printing of LabVIEW strings to any Windows printer, serial port enumeration, pipe implementation and a few other things like network MAC and CPUID retrieval in about 32kB :P.

Then why not offer it as a solution to this users request? I didn't see anyone offering a solution, so proffered this since I had to do it anyway.

I don't see the point in making miniscule dlls called from labview since you have to install a couple of hundred megs of labview rubbish, so whats an extra few kilobytes? I could have got it down even further (the dll is actually a wrapper around a VCL component) but 162 KB is fine without spending more time on it and having separate source. Saying that. I did recently download a Matrix screensaver for Pelles which was only 56KB when compiled. That was impressive!:worshippy:

I have another VI named "Get hard disk volume info" work well in my system.

What Rolf said! The OP did say that he didn't want the volume information serial.

Edited by ShaunR
Link to comment

Then why ask if ists a .NET dll :unsure:

Because I hadn't looked closer at it at that point. :rolleyes:

Then why not offer it as a solution to this users request? I didn't see anyone offering a solution, so proffered this since I had to do it anyway.

Because my solution didn't work properly at that time. I had in the past tried to make modifications to get around the admins-right limitation and the whole thing was not compiling at all. And the older version I had running did not have the MACaddress and HD Serial option. I got it back running with the admins right limitation in the mean time, after looking at your DLL and recognizing the IOCTL operations, but circumventing the admins problem is tricky to solve for all HDs and supposedly going to fail in Vista/Windows 7 again, so not a very high priority for me to get this done.

I don't see the point in making miniscule dlls called from labview since you have to install a couple of hundred megs of labview rubbish, so whats an extra few kilobytes? I could have got it down even further (the dll is actually a wrapper around a VCL component) but 162 KB is fine without spending more time on it and having separate source. Saying that. I did recently download a Matrix screensaver for Pelles which was only 56KB when compiled. That was impressive!:worshippy:

Yes I'm also not saying that a DLL needs to be miniscule. But I like to see what is possible and find it interesting to try to not get unneccessary stuff linked in my DLLs. One possibility for this is to still use VC 6. Not because it creates compacter code than VC 2008 (it most probably does a worse job than 2008) but because it's runtime is also much smaller and can without any trouble be selected to be dynamically linked. For Borland C, Delphi and VC 2008, you probably have to include the C runtime in the link to make sure that you do not need to distribute an additional runtime library installer.

Rolf Kalbermatter

Link to comment

If the application requires a piece of hardware, such as a DAQ card, you can use its serial number.

Unfortunately, not everyone uses NI products with LV.

Anyhoo.

New build. Works without Admin rights (well, on my Windows7 x64 and Vista Ultimate x64). Tested so far on the only have 2 drives at at the moment (A western digital and Hitachi).

See how you get on.

Link to comment

Unfortunately, not everyone uses NI products with LV.

Anyhoo.

New build. Works without Admin rights (well, on my Windows7 x64 and Vista Ultimate x64). Tested so far on the only have 2 drives at at the moment (A western digital and Hitachi).

See how you get on.

I see you are using the IOCTL_STORAGE_DISK ioctl codes now. Unfortunately that seems not to work for some (all?) SATA drives, at least on my computer the serial number field always remains empty using that method.

This seems to be a known issue with the STORAGE class device driver API not returning the serial number for SATA drives. In short all my research has not brought any reliable method to return the serial number both without admin rights and for all types of built in drives. Don't even talk about USB connected drives, they return the model number devided up in vendor ID and ProductID, which have a meaningful meaning for USB sticks, but divide the ModelID into two parts for USB connected HDs and never return any serial number.

Maybe they improved the storage device driver API in Win7 to also return the serial number but at least on XP it will not work for SATA drives.

Rolf Kalbermatter

Link to comment

I see you are using the IOCTL_STORAGE_DISK ioctl codes now. Unfortunately that seems not to work for some (all?) SATA drives, at least on my computer the serial number field always remains empty using that method.

This seems to be a known issue with the STORAGE class device driver API not returning the serial number for SATA drives. In short all my research has not brought any reliable method to return the serial number both without admin rights and for all types of built in drives. Don't even talk about USB connected drives, they return the model number devided up in vendor ID and ProductID, which have a meaningful meaning for USB sticks, but divide the ModelID into two parts for USB connected HDs and never return any serial number.

Maybe they improved the storage device driver API in Win7 to also return the serial number but at least on XP it will not work for SATA drives.

Rolf Kalbermatter

The two drives tested are SATA. So maybe what you are seeing is peculiar to XP. I'll take one of the laptops from work home and see what happens. I wasn't particularly looking at USB drives since they can be moved from PC to PC, but in my wanderings I did notice they don't give a serial (serialoffset=0). It is looking like the only reiable way is to walk the registry and look at the device ID (was hoping to avoid that since to me it seems tacky), but if I do go that route, at least it will also get the USB drives (I already have a detect USB drive insertion that works of 7,vista and XP that uses that method).

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.