Help with this form

elliot315

Mr. Question
Local time
Today, 13:34
Joined
Jun 3, 2007
Messages
98
I found this code, it is supposed to get the serial number of the HDD
I want to create a form that shows me that serial number to create an unlocking code for that installed db.
Any help on this will be appreciated.. where do I have to put this code, how to create the form that shows me the serial number, how to accept the unlocking number based on the math formula, and how to make this form not to appear after entering the correct code... I'm new in the scene of Access so I need very detailed instructions, thanks.

Private Const MAX_PATH = 260

Function fVolume1(strDriveLetter As String) As String
' Function to return the volume label for a drive
' Accepts:
' strDriveLetter - a valid drive letter for the PC, in the format "C:\"
' Returns:
' The volume label if it exists, or else "No label"
Dim strVolume As String
strVolume = Dir(strDriveLetter, vbVolume)
If strVolume = "" Then strVolume = "No label"
fVolume1 = strVolume
End Function

Function fVolume2(strDriveLetter As String) As String
' Function to return the volume label for a drive
' Accepts:
' strDriveLetter - a valid drive letter for the PC, in the format "C:\"
' Returns:
' The volume label if it exists, or else "No label"
Dim lngReturn As Long, lngDummy1 As Long, lngDummy2 As Long, lngDummy3 As Long
Dim strVolume As String, strDummy As String
strVolume = Space(MAX_PATH)
strDummy = Space(MAX_PATH)
lngReturn = apiGetVolumeInformation(strDriveLetter, strVolume, Len(strVolume), lngDummy1, lngDummy2, lngDummy3, strDummy, Len(strDummy))
strVolume = Left(strVolume, InStr(strVolume, vbNullChar) - 1)
If strVolume = "" Then strVolume = "No label"
fVolume2 = strVolume
End Function

Function fSerialNumber(strDriveLetter As String) As String
' Function to return the serial number for a hard drive
' Accepts:
' strDriveLetter - a valid drive letter for the PC, in the format "C:\"
' Returns:
' The serial number for the drive, formatted as "xxxx-xxxx"
Dim lngReturn As Long, lngDummy1 As Long, lngDummy2 As Long, lngSerial As Long
Dim strDummy1 As String, strDummy2 As String, strSerial As String
strDummy1 = Space(MAX_PATH)
strDummy2 = Space(MAX_PATH)
lngReturn = apiGetVolumeInformation(strDriveLetter, strDummy1, Len(strDummy1), lngSerial, lngDummy1, lngDummy2, strDummy2, Len(strDummy2))
strSerial = Trim(Hex(lngSerial))
strSerial = String(8 - Len(strSerial), "0") & strSerial
strSerial = Left(strSerial, 4) & "-" & Right(strSerial, 4)
fSerialNumber = strSerial
End Function
 
The code you posted is a little lite on declarations. Try putting this is a standard module by itself named HDDcode.
Code:
Option Compare Database
Option Explicit

Private Declare Function apiGetVolumeInformation _
                          Lib "kernel32" Alias "GetVolumeInformationA" _
                              (ByVal lpRootPathName As String, _
                               ByVal lpVolumeNameBuffer As String, _
                               ByVal nVolumeNameSize As Long, _
                               lpVolumeSerialNumber As Long, _
                               lpMaximumComponentLength As Long, _
                               lpFileSystemFlags As Long, _
                               ByVal lpFileSystemNameBuffer As String, _
                               ByVal nFileSystemNameSize As Long) As Long

Private Const MAX_PATH = 260

Function fVolume1(strDriveLetter As String) As String
' Function to return the volume label for a drive
' Accepts:
' strDriveLetter - a valid drive letter for the PC, in the format "C:\"
' Returns:
' The volume label if it exists, or else "No label"
   Dim strVolume As String
   strVolume = Dir(strDriveLetter, vbVolume)
   If strVolume = "" Then strVolume = "No label"
   fVolume1 = strVolume
End Function

Function fVolume2(strDriveLetter As String) As String
' Function to return the volume label for a drive
' Accepts:
' strDriveLetter - a valid drive letter for the PC, in the format "C:\"
' Returns:
' The volume label if it exists, or else "No label"
   Dim lngReturn As Long, lngDummy1 As Long, lngDummy2 As Long, lngDummy3 As Long
   Dim strVolume As String, strDummy As String
   strVolume = Space(MAX_PATH)
   strDummy = Space(MAX_PATH)
   lngReturn = apiGetVolumeInformation(strDriveLetter, strVolume, Len(strVolume), lngDummy1, lngDummy2, lngDummy3, strDummy, Len(strDummy))
   strVolume = Left(strVolume, InStr(strVolume, vbNullChar) - 1)
   If strVolume = "" Then strVolume = "No label"
   fVolume2 = strVolume
End Function

Public Function fSerialNumber(strDriveLetter As String) As String
' Function to return the serial number for a hard drive
' Accepts:
' strDriveLetter - a valid drive letter for the PC, in the format "C:\"
' Returns:
' The serial number for the drive, formatted as "xxxx-xxxx"
   Dim lngReturn As Long, lngDummy1 As Long, lngDummy2 As Long, lngSerial As Long
   Dim strDummy1 As String, strDummy2 As String, strSerial As String
   strDummy1 = Space(MAX_PATH)
   strDummy2 = Space(MAX_PATH)
   lngReturn = apiGetVolumeInformation(strDriveLetter, _
                                       strDummy1, _
                                       Len(strDummy1), _
                                       lngSerial, _
                                       lngDummy1, _
                                       lngDummy2, _
                                       strDummy2, _
                                       Len(strDummy2))
   strSerial = Trim(Hex(lngSerial))
   strSerial = String(8 - Len(strSerial), "0") & strSerial
   strSerial = Left(strSerial, 4) & "-" & Right(strSerial, 4)
   fSerialNumber = strSerial
End Function
Then open the immediate window and key in:
?fSerialNumber("c:\") and see what happens.
 
I really didn't understand that:
Then open the immediate window and key in:
?fSerialNumber("c:\") and see what happens.
 
While looking at the code in your standard module hit <CTRL>G (^G). That opens the immediate window. Then type in that window:
?fSerialNumber("c:\")
and see what happens. Post back if you still need some assistance.
 
ok it shows the serial number.. ok thanks so far... now.. how do I write the code to show me that number in a form (the unlocking db form)
and please a sample of a login form
 
If you create a form with a TextBox control on it and set the ControlSource of the TextBox to: =fSerialNumber("c:\") then it will display the SerialNumber in that TextBox. As for a login form, there are tons of examples on this forum. Just search for them.
 

Users who are viewing this thread

Back
Top Bottom