Tutorial
kali ini akan menjelaskan bagaimana membuat contoh form aktivasi, yaitu form yang
berfungsi untuk melakukan aktivasi software aplikasi yang kita buat. Dimana biasanya dalam form terdapat dua bagian penting yaitu Serial Number dan Activation Key. Serial Number akan unik disetiap komputer, sehingga dibutuhkan Activation Key yang unik pula.
Untuk mendapatkan Activation Key bisa gunakan tombol Generate, namun jangan lupa untuk menghapus/men-disabled tombol Generate agar tidak bisa diakses oleh pengguna software yang kita buat.
- Silahkan desain form seperti gambar di bawah ini, dan buat property name nya seperti pada gambar.
Imports Microsoft.Win32
Public Class ACTIVATION_FORM
Private Sub ACTIVATION_FORM_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim
serial As Long
Dim
sm As New SecurityManager
Dim
temp As String
Dim
pjg As Integer
Dim
newSerial As String = ""
serial = sm.GetSerial
temp = serial
pjg = temp.Length
For
i As Integer = 1 To pjg
Dim
a As String
Dim
b As Integer
a = Mid(temp, i, 1)
b = Asc(a)
newSerial = newSerial & a &
b Mod 2
Next
serialTextBox.Text = newSerial
checkLicense()
Dim
kg As New KeyGenerator
Dim
key As String = kg.GenerateKey(serialTextBox.Text)
If
activationKeyTextBox.Text <> key Then
statusLabel.ForeColor = Color.Red
statusLabel.Text = "Not Activated/invalid
key"
Button1.Enabled = True
Else
statusLabel.ForeColor = Color.DarkGreen
statusLabel.Text = "Activated"
Button1.Enabled = False
End
If
End
Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Me.Close()
End
Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
'Dim serial As Long
'If Not Long.TryParse(serialTextBox.Text, serial) Then
'MessageBox.Show("Inavlid serial number")
'Exit Sub
'End If
Dim
kg As New KeyGenerator
Dim
key As String =
kg.GenerateKey(serialTextBox.Text)
activationKeyTextBox.Text = key
End
Sub
Sub
checkLicense()
Dim
kg As New KeyGenerator
Dim
key As String =
kg.GenerateKey(serialTextBox.Text)
If
System.IO.File.Exists(bejoLicenseFile) Then
bejoWriteSettings(bejoLicenseFile, "LICENSE", "serial", serialTextBox.Text)
activationKeyTextBox.Text =
bejoReadSettings(bejoLicenseFile, "LICENSE", "activation_key", "")
Else
bejoWriteSettings(bejoLicenseFile, "LICENSE", "serial", serialTextBox.Text)
activationKeyTextBox.Text = ""
End
If
End
Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim
kg As New KeyGenerator
Dim
key As String =
kg.GenerateKey(serialTextBox.Text)
If
activationKeyTextBox.Text <> key Then
statusLabel.ForeColor = Color.Red
statusLabel.Text = "Not Activated/invalid
key"
MsgBox("Invalid activation
key!", vbExclamation)
Else
bejoWriteSettings(bejoLicenseFile, "LICENSE", "activation_key", activationKeyTextBox.Text)
statusLabel.ForeColor = Color.DarkGreen
statusLabel.Text = "Activated"
MsgBox("Successfull
Activated!",
vbInformation)
End
If
End
Sub
End Class
- Tambahkan Module1 pada project dan copy source code berikut :Module Module1Public bejoDirectory As String = My.Application.Info.DirectoryPathPublic bejoLicenseFile As String = bejoDirectory & "\license.ini"Private Declare Unicode Function GetPrivateProfileString Lib "kernel32" _Alias "GetPrivateProfileStringW" (ByVal lpApplicationName As String, _ByVal lpKeyName As String, ByVal lpDefault As String, _ByVal lpReturnedString As String, ByVal nSize As Int32, _ByVal lpFileName As String) As Int32Private Declare Unicode Function WritePrivateProfileString Lib "kernel32" _Alias "WritePrivateProfileStringW" (ByVal lpApplicationName As String, _ByVal lpKeyName As String, ByVal lpString As String, _ByVal lpFileName As String) As Int32Public Sub bejoWriteSettings(ByVal iniFileName As String, ByVal Section As String, ByVal ParamName As String, ByVal ParamVal As String)Dim Result As Integer = WritePrivateProfileString(Section, ParamName, ParamVal, iniFileName)End SubPublic Function bejoReadSettings(ByVal IniFileName As String, ByVal Section As String, ByVal ParamName As String, ByVal ParamDefault As String) As StringDim ParamVal As String = Space$(1024)Dim LenParamVal As Long = GetPrivateProfileString(Section, ParamName, ParamDefault, ParamVal, Len(ParamVal), IniFileName)bejoReadSettings = Left$(ParamVal, LenParamVal)End FunctionEnd Module
- Pada menu Project > Add References (beri tick pada System.Management)
- Tambahkan object Class pada project simpan dengan nama KeyGenerator.vb, lalu copy code berikut :Public Class KeyGeneratorPublic Function GenerateKey(ByVal serial As String) As StringDim x As String = serialDim temp As String = x * x / (x / 2) + x / 193686Dim a As String = ""For i As Integer = 0 To temp.Length - 1Dim s As Char = temp.Substring(i, 1)If s = "," Or s = "." Thena = a & Asc(".")Elsea = a & Asc(temp.Substring(i, 1))End IfNextDim b As String = a.Substring(0, 5) & "-" & a.Substring(5, 5) & "-" & a.Substring(10, 5) & "-" & a.Substring(15, 5) & "-" & a.Substring(20, 5)Return bEnd FunctionEnd Class
- Tambahkan object Class pada project simpan dengan nama SecurityManager.vb, lalu copy code berikut :Imports System.ManagementPublic Class SecurityManagerPublic Function GetSerial() As LongDim mc As New ManagementClass("Win32_NetworkAdapterConfiguration")Dim mac As String = ""Dim moc As ManagementObjectCollection = mc.GetInstancesFor Each mo As ManagementObject In mocIf mo.Item("IPEnabled") Thenmac = mo.Item("MacAddress").ToStringEnd IfNextmc.Dispose()Dim sum As Long = 0Dim index As Integer = 1For Each ch As Char In macIf Char.IsDigit(ch) Thensum += sum + Integer.Parse(ch) * (index * 2)ElseIf Char.IsLetter(ch) ThenSelect Case ch.ToString.ToUpperCase "A"sum += sum + 10 * (index * 2)Case "B"sum += sum + 11 * (index * 2)Case "C"sum += sum + 12 * (index * 2)Case "D"sum += sum + 13 * (index * 2)Case "E"sum += sum + 14 * (index * 2)Case "F"sum += sum + 15 * (index * 2)End SelectEnd Ifindex += 1NextReturn sumEnd FunctionPublic Function CheckKey(ByVal key As Long) As BooleanDim x As Long = GetSerial()Dim y As Long = x * x + 53 / x + 113 * (x / 4)Return y = keyEnd FunctionEnd Class
Yang mau download project nya dan papernya download di bawah ini :