Jump to content
Xtreme .Net Talk

Recommended Posts

Posted (edited)

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?

Edited by EFileTahi-A
Posted

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.

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

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:

'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

~Nate�

___________________________________________

Please use the [vb]/[cs] tags on posted code.

Please post solutions you find somewhere else.

Follow me on Twitter here.

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