Generating a software key based on hardware

EFileTahi-A

Contributor
Joined
Aug 8, 2004
Messages
623
Location
Portugal / Barreiro
I thought I could easly do this by retrieving the MacAddress of a computer, but, stupid me, if the computer does not have Network card there is no MacAddress.

So what I need is to generate a code based on an unique value of a computer. I just need to know which unique value(s) can I get from the system in order to me to generate a key based in the very same value...

If the solution for this is to get all hardware ID, how can I do this?
 
Last edited:
Here's how to get the unique ID of the harddrive; and hopfully all computers will have one of these. I've used this for some demo projects that I wanted to only run on the demo computer at a trade show...


Whenever a disk is formatted, the operating system writes a serial number onto it. This number is not guaranteed to be unique, but as it is a 32 bit integer it is unlikely to find a duplicate! The number is often used as part of a copy protection system. This tip shows you how to retrieve the number.
Declarations

Copy this code into the declarations section of the project.
Visual Basic:
Private Declare Function GetVolumeInformation Lib _
"kernel32.dll" Alias "GetVolumeInformationA" (ByVal _
lpRootPathName As String, ByVal lpVolumeNameBuffer As _
String, ByVal nVolumeNameSize As Integer, _
lpVolumeSerialNumber As Long, lpMaximumComponentLength _
As Long, lpFileSystemFlags As Long, ByVal _
lpFileSystemNameBuffer As String, ByVal _
nFileSystemNameSize As Long) As Long
Code
Visual Basic:
Function GetSerialNumber(strDrive As String) As Long
    Dim SerialNum As Long
    Dim Res As Long
    Dim Temp1 As String
    Dim Temp2 As String
    Temp1 = String$(255, Chr$(0))
    Temp2 = String$(255, Chr$(0))
    Res = GetVolumeInformation(strDrive, Temp1, _
    Len(Temp1), SerialNum, 0, 0, Temp2, Len(Temp2))
    GetSerialNumber = SerialNum
End Function
Use

An example of using the above function:
Visual Basic:
'EDIT- Fixed the \\ not showing up by adding a second \\
Call MsgBox GetSerialNumber("C:\\")
This will bring up a message box with the serial number of the C drive.

View The Original Entry Here
 
Back
Top