Results 1 to 2 of 2

Thread: Reading GUID

  1. #1

    Thread Starter
    Fanatic Member Kzin's Avatar
    Join Date
    Dec 2000
    Posts
    611

    Question

    Does anyone know a simple way for a VB6 Active X EXE to read a unique identifier from a machine (particularly the HDD GUID) for anti-piracy. I gues one could do it using the registry but it would be much better if there is a more robust way that does not involve downloading an extra DLL just for the purpose.

  2. #2

    Thread Starter
    Fanatic Member Kzin's Avatar
    Join Date
    Dec 2000
    Posts
    611

    Thumbs up This works

    Retrieving a disk's serial number
    --------------------------------------------------------------------------------
    Add this code to a new module:
    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

    Function GetSerialNumber(sDrive As String) As Long
    Dim lSerial As Long
    Dim lRetVal As Long
    Dim sTempA As String
    Dim sTempB As String
    sTempA = String$(255, Chr$(0))
    sTempB = String$(255, Chr$(0))
    lRetVal = GetVolumeInformation(sDrive, sTempA, Len(sTempA), lSerial, 0, 0, sTempB, Len(sTempB))
    GetSerialNumber = lSerial
    End Function

    The GetVolumeInformation function also allows you to get other information about a disk, not only it's serial number, but most of the other parts are normally unused (unless you're a real power user)
    To use this function, simply call when necessary:
    Dim lSerialNum as Long
    ...
    Private Sub Form_Load()
    lSerialNum = GetSerialNumber("C:\")

    ' Do something with the serial number, for example check that
    ' this computer is authorised to use the program
    End Sub


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width