codice:
'in un form
Option Explicit
Dim Serial_Number As String
Dim Activation_Code As String
Dim Get_Serial_From_Registry As String
Dim Get_Date_From_Registry As String
Dim Shareware_Number As String
Private Sub Form_Load()
Serial_Number = GetDriveInfo("C:\", 1) ' HD Serial Number
Shareware_Number = "555xc3"
'semplici calcoli per calcolare il codice di attivazioneù
Activation_Code = Left(Serial_Number, 4)
Activation_Code = Activation_Code * 881999
Activation_Code = Left(Activation_Code, 6)
'controlla se l'user si è gia registrato
Get_Serial_From_Registry = GetSetting(App.EXEName, "Registration", "Code")
If Activation_Code = Get_Serial_From_Registry Then
Unload Me
Call Main
'Altrimenti mostra questa finestra ed imposta il serial_number
ElseIf Shareware_Number = Get_Serial_From_Registry Then
Get_Date_From_Registry = GetSetting(App.EXEName, "Registration", "Date")
If (Date - CDate(Get_Date_From_Registry)) > 30 Then
SaveSetting App.EXEName, "Registration", "Code", "xxx"
lbl_HD_Serial_Number = Serial_Number
Exit Sub
End If
Unload Me
Call Main
ElseIf "xxx" = Get_Serial_From_Registry Then
lbl_HD_Serial_Number = Serial_Number
Exit Sub
Else
lbl_HD_Serial_Number = Serial_Number
End If
End Sub
Private Sub cmdCheck_Click()
Dim Res, Msg
'Controllo Serial
If Activation_Code = Trim(txtSerial) Then
SaveSetting App.EXEName, "Registration", "Code", txtSerial
SaveSetting App.EXEName, "Registration", "Date", Date
Msg = "Grazie per la tua registrazione. Tieni questo codice in un luogo sicuro."
Res = MsgBox(Msg, vbInformation, "Grazie")
'frmMainHD.Text1 = Serial_Number
'frmMainHD.Text2 = Activation_Code
Call Main
Unload Me
'frmMainHD.Show
ElseIf Shareware_Number = Trim(txtSerial) Then
Get_Serial_From_Registry = GetSetting(App.EXEName, "Registration", "Code")
If Get_Serial_From_Registry = "xxx" Then
txtSerial = ""
MsgBox " Tempo di prova terminato!" & vbCr & _
"Se si desidera licenziare il programma inserire il codice fornito dal produttore" _
, 0 + 0 + 16 + 0, _
App.EXEName & " " & App.Major & Format(App.Minor, "00")
Exit Sub
Else
SaveSetting App.EXEName, "Registration", "Code", txtSerial
SaveSetting App.EXEName, "Registration", "Date", Date
End If
Call Main
Unload Me
Else
Res = MsgBox("Il tuo codice di attivazione non è valido", vbInformation, "Errore!")
txtSerial.SetFocus
End If
End Sub
' in un modulo
Declare Function GetVolumeInformation Lib "kernel32" Alias "GetVolumeInformationA" _
(ByVal lpRootPathName As String, ByVal lpVolumeNameBuffer As String, _
ByVal nVolumeNameSize As Long, lpVolumeSerial_Numberber As Long, _
lpMaximumComponentLength As Long, lpFileSystemFlags As Long, _
ByVal lpFileSystemNameBuffer As String, ByVal nFileSystemNameSize As Long) As Long
Public Const GETDI_SERIAL = 1
Public Const GETDI_LABEL = 2
Public Const GETDI_TYPE = 3
Function GetDriveInfo(strDrive As String, iType As Integer)
Dim Serial_Number As Long
Dim Drive_Label As String
Dim Fat_Type As String
Dim Return_Value As Long
Drive_Label = Space(256)
Fat_Type = Space(256)
Return_Value = GetVolumeInformation(strDrive, Drive_Label, Len(Drive_Label), Serial_Number, 0, 0, Fat_Type, Len(Fat_Type))
GetDriveInfo = CStr(Serial_Number)
End Function