retrieving a unique ID for your system. code included.
Hi all,
Have seen numerous posts on this forum about how to obtain some kind of unique ID to identify a particular computer so developers can better protect their software with serial numbers etc.
Well, I have put together some code that might help people achieve this in some way.
I have come up with 5 functions (all written exclusively in VB), that can retrieve a unique value for a given system:
- GetBIOSSerial() ' serial number from BIOS on motherboard
- GetMACAddress() ' serial number from first ethernet card
- GetHardDriveSerial(IDE_NUMBER) ' Hard Drive serial number
- GetVolumeSerial(Drive) ' Formatted partition serial number
- GetProductID() ' Windows product ID
Unfortunately tho (there is always a downside) only 2 of these functions are guarunteed to return a value on all versions of Windows (GetVolumeSerial, and GetProductID).
GetBIOSSerial() may work depending on the BIOS, or it may just be it doesnt work on Win98 or earlier (I have only been able to test this on 3 machines so far, 2 Win98 machines which fail, and a Win2K machine which works). If anyone can further add to this, that would be great.
GetMACAddress() retrieves the MAC Address of an ethernet adapter which is guaranteed to be globally unique, however, in Win95 and WinNT, the card appears to need to be connected to the network. In Win2K and WinXP, the ethernet card must be enabled but doesnt have to be connected. Also, ID's may still be returned for Virtual Networks, and I dont know if these can be guaranteed to be globally unique or only on the current network. If anyone can further add to this, please do
GetHardDriveSerial(IDE_NUMBER) returns the serial number for the physical hard drive connected to one of your 4 IDE channels (ie, PRIMARY_MASTER, PRIMARY_SLAVE, SECONDARY_MASTER, SECONDARY_SLAVE). This is not the same as the volume serial number which is assigned when formatting a partition on your hard drive. Again, I have only been able to test this on 3 machines, and it has worked on 2 of them, a Win98 machine, and a Win2K machine).
GetVolumeSerial(Drive) returns the above mentioned serial number assigned to a partition when you format it. This function appears to work on all OS's, but will be changed if you reformat your hard drive. If no Drive is specified, it checks the partition the system is installed on.
GetProductID() returns the Windows Product ID. Granted, GetProductID may not be globally unique, but can be a useful ID to use if you want to combine some of these functions together. I am not sure if this value is the same for all computers who have had Windows installed from the same CD or not (perhaps someone can clarify this). Also, this value is stored in the registry, and might be easily modified (does Windows allow it to be modified, and does it cause problems in Windows if it is changed? Perhaps someone can clarify this too).
There are still a few questions to answer, which is why I have posted it up here on this forum. I have attached the code for people to test on different systems. It would be good to have a more definite idea on which OS's the different functions will work on, and how reliable they are.
Please feel free to suggest changes if there are bugs, or if you know of other values or IDs that can be added to this code base, or if there are more reliable ways to retrieve the values in these functions for different OS's.
It should also be noted, that when using the code, it would probably be safer to include it in your own project rather than as a separate DLL, unless you compress it and add a CRC32 checker to it. But even then, the best of the best can still work their way around it. But we should at least make them work for it
Cheers everyone, hope to hear peoples input on these functions.
Tinbum747.
Zen-Programming:
If a compiler beeps in the IDE forest, and nobody hears it, was there really a bug?
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.