How To Create Trial Program In Visual Studio
Preview
Hello friends, sometimes if we've created an app, we certainly want to protect it from hijackers. In this post I will discuss about how to create an activation program by reading the processor code on the device used, then perform the encryption process.
First open Visual Studio and create a new project, then design the form as shown below
Add one more Form named Form2 then enter the Timer into it.
Now, go back to Form1 and add System.Management library. Right click the project and select Add Reference, click the .NET Tab then scroll down until you find System.Management and click OK
Now, go into the code and declare some global variables needed
Public Class Form1
Dim Win32MnClass As System.Management.ManagementClass
Dim processors As System.Management.ManagementObjectCollection
Dim Enkrip, Output, Inputan, hasilenkripsi, prosesor As String
Dim Panjang_Input As Integer
End Class
After that, we will read the proccessor code on the device we use then we display it into Textbox1.
Double-click Form1 and enter the following code into the Form_Load
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Win32MnClass = New System.Management.ManagementClass("Win32_Processor")
processors = Win32MnClass.GetInstances()
For Each processor As System.Management.ManagementObject In processors
prosesor = (processor("ProcessorID").ToString())
TextBox1.Text = prosesor
Next
End Sub
And at the same time, the program will detect whether the device used has been activated or not. If not, the program will display a warning message and stay in Form1, If it is, then Form1 will be hidden and Form2 will appear.
You just added some more code below
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Win32MnClass = New System.Management.ManagementClass("Win32_Processor")
processors = Win32MnClass.GetInstances()
For Each processor As System.Management.ManagementObject In processors
prosesor = (processor("ProcessorID").ToString())
TextBox1.Text = prosesor
Next
Inputan = prosesor
Panjang_Input = Len(Inputan)
For i = 1 To Panjang_Input
Enkrip = Mid(Inputan, i, 1)
Enkrip = Asc(Enkrip)
Enkrip = (Enkrip + 20) - 43
Enkrip = Chr(Enkrip)
Output = Output & Enkrip
Next i
hasilenkripsi = Output
If My.Computer.Registry.GetValue("HKEY_CURRENT_USER\" + hasilenkripsi, "Andi", "Aspin") Is Nothing Then
MessageBox.Show("Activation Code Not Detected", "Warning !!", MessageBoxButtons.OK, MessageBoxIcon.Error)
Else
Me.Hide()
Form2.Timer1.Enabled = False
Form2.ShowDialog()
End If
End Sub
NOTES :
some additional code above serves to perform the encryption process of the proccessor code, then stored into the hasilenkripsi variable.
then, the value of the hasilenkripsi variable will be stored in the Windows Registry Editor (Regedit) in the HKEY_CURRENT_USER folder.
Now, double-click Button 2 and enter the following code, so that the user can skip the activation process and enter into Form2 but within a certain time.some additional code above serves to perform the encryption process of the proccessor code, then stored into the hasilenkripsi variable.
then, the value of the hasilenkripsi variable will be stored in the Windows Registry Editor (Regedit) in the HKEY_CURRENT_USER folder.
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Me.Visible = False
Form2.ShowDialog()
End Sub
Then, double-click Button 1 and enter the following code, to match whether the activation code entered in Textbox2 is equal to the value of the hasilenkripsi variable. If appropriate, then Form1 will be hidden and Form2 will appear without time limit, otherwise it will display a warning message.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If TextBox2.Text = hasilenkripsi Then
My.Computer.Registry.SetValue("HKEY_CURRENT_USER\" + hasilenkripsi, "Andi", "Aspin")
MessageBox.Show("Activation Code is correct", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information)
Me.Visible = False
Form2.Timer1.Enabled = False
Form2.ShowDialog()
Else
MsgBox("Activation Code is incorrect", MsgBoxStyle.Exclamation)
End If
End Sub
And finally, open Form2 and change the Timer1 properties to Enabled : True. Then double-click Timer1 and enter the following code
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Static iCount As Integer
If iCount = 50 Then
iCount = 0
Me.Dispose()
Form1.Dispose()
Else
iCount = iCount + 1
End If
End Sub
NOTES :
The above code works if Timer1 Enabled: True then Form2 can only appear for 5 seconds, If Timer1 Enabled: False then Form2 will appear without time limit.
You can change 5 seconds to 10 seconds (for example) by changing 50 to 100.
When finished, the program is ready to runThe above code works if Timer1 Enabled: True then Form2 can only appear for 5 seconds, If Timer1 Enabled: False then Form2 will appear without time limit.
You can change 5 seconds to 10 seconds (for example) by changing 50 to 100.