locked
Permanent Activated RRS feed

  • Question

  • Please help me 

    I found this code from code project website

    i want to use this code for security reason

    my problem is when i input the activation code MessageBox.Show("Activation was successful") but when i execute again

    its always my form5 show not my main form

    Public Class Form5
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Dim serial As Long
            Dim sm As New SecurityManager
            serial = sm.GetSerial
            txtSerial.Text = serial
        End Sub

        Private Sub btnActivate_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnActivate.Click
            Dim key As Long
            If Not Long.TryParse(txtKey.Text, key) Then
                MessageBox.Show("Invalid activation key")
                
                Me.Hide()
                Exit Sub
            End If

            Dim sm As New SecurityManager
            If sm.CheckKey(key) Then

                MessageBox.Show("Activation was successful")

                
            Else
                MessageBox.Show("Activation was unsuccessful")
                Me.Hide()
            End If
        End Sub

       
    End Class

    Friday, April 25, 2014 2:41 PM

Answers

  • The project directly from the website works exactly as intended as best as I can tell. I have no idea what form5 is so I cannot comment on that.

    you should probably save the activation key once it has been entered successfully. Whatever form is the startup can check this stored value and if correct, load your main form or continue with the startup form and if not, load the "Enter Activation Key" form.

    Look at My.Settings here

    My opinion is also that naming forms with names like Form1, Form2, etc just makes it harder to see where you are. Why not use names like "FormMain", "FormEnterKey", etc ? Same with controls. I have seen projects with 20 or more textboxes named with the default. Bad bad practice in my opinion.

    • Proposed as answer by Cor Ligthert Saturday, April 26, 2014 12:27 PM
    • Marked as answer by Carl Cai Monday, May 5, 2014 5:22 PM
    Saturday, April 26, 2014 5:30 AM
  • hi frank many thanks for your effort this is very helpful to me

    but i dont know how to make key generator using your sample project

    and how did you get the activation code?

    Their activation code is their own MAC address, encrypted (two different encryptions).

    Please re-read what I wrote - I thought it was pretty clear.


    Please call me Frank :)

    • Marked as answer by s.pac Thursday, May 22, 2014 1:43 PM
    Thursday, May 22, 2014 12:27 PM
  • s,

    If you're going to use hardware-based activation based on the user's MAC address, maybe give this a try.

    I haven't fully tested it, but I think it should work ok based on my preliminary tests.

    If you want me to explain what's going on (or how to add it to your program and/or how to use it), just let me know:

    Option Strict On Option Explicit On Imports System.Security.Cryptography Imports System.Management Imports System.IO.Path Imports System.Environment Namespace Activation ''' <summary> ''' A class for simple encryption as per MSDN document shown at: ''' http://msdn.microsoft.com/en-us/library/ms172831(v=vs.90).aspx ''' </summary> ''' <remarks></remarks> Public NotInheritable Class Simple3Des Private TripleDes As New TripleDESCryptoServiceProvider Sub New(ByVal key As String) ' Initialize the crypto provider. TripleDes.Key = TruncateHash(key, TripleDes.KeySize \ 8) TripleDes.IV = TruncateHash("", TripleDes.BlockSize \ 8) End Sub Public Function EncryptData(ByVal plaintext As String) _ As String ' Convert the plaintext string to a byte array. Dim plaintextBytes() As Byte = _ System.Text.Encoding.Unicode.GetBytes(plaintext) ' Create the stream. Dim ms As New System.IO.MemoryStream ' Create the encoder to write to the stream. Dim encStream As New CryptoStream(ms, _ TripleDes.CreateEncryptor(), _ System.Security.Cryptography.CryptoStreamMode.Write) ' Use the crypto stream to write the byte array to the stream. encStream.Write(plaintextBytes, 0, plaintextBytes.Length) encStream.FlushFinalBlock() ' Convert the encrypted stream to a printable string. Return Convert.ToBase64String(ms.ToArray) End Function Public Function DecryptData(ByVal encryptedtext As String) _ As String ' Convert the encrypted text string to a byte array. Dim encryptedBytes() As Byte = Convert.FromBase64String(encryptedtext) ' Create the stream. Dim ms As New System.IO.MemoryStream ' Create the decoder to write to the stream. Dim decStream As New CryptoStream(ms, _ TripleDes.CreateDecryptor(), _ System.Security.Cryptography.CryptoStreamMode.Write) ' Use the crypto stream to write the byte array to the stream. decStream.Write(encryptedBytes, 0, encryptedBytes.Length) decStream.FlushFinalBlock() ' Convert the plaintext stream to a string. Return System.Text.Encoding.Unicode.GetString(ms.ToArray) End Function Private Function TruncateHash(ByVal key As String, _ ByVal length As Integer) _ As Byte() Dim sha1 As New SHA1CryptoServiceProvider ' Hash the key. Dim keyBytes() As Byte = _ System.Text.Encoding.Unicode.GetBytes(key) Dim hash() As Byte = sha1.ComputeHash(keyBytes) ' Truncate or pad the hash. ReDim Preserve hash(length - 1) Return hash End Function End Class Public Class UserMAC Private Shared programDataFolderPath As String = _ Combine(GetFolderPath(SpecialFolder.ApplicationData), _ My.Application.Info.AssemblyName) Private Shared encMAC_Path As String = Combine(programDataFolderPath, "encM.h") Public Delegate Function GetMACAddressDelegate() As String ' <summary> ' This will return this user's MAC address as a string. ' </summary> ' <returns></returns> ' <remarks></remarks> Public Shared Function GetMACAddress() As String ' Note that you will need to add a reference to ' System.Management for this to work. Dim retVal As String = Nothing Try Dim mc As New ManagementClass("Win32_NetworkAdapterConfiguration") Dim moc As ManagementObjectCollection = mc.GetInstances() Dim MACAddress As String = "" For Each mo As ManagementObject In moc If MACAddress = "" Then ' Only return MAC Address from first card: If CBool(mo("IPEnabled")) Then MACAddress = mo("MacAddress").ToString() mo.Dispose() Exit For End If End If mo.Dispose() Next moc.Dispose() mc.Dispose() retVal = MACAddress.Replace(":", "") Catch ex As Exception retVal = Nothing End Try Return retVal End Function ''' <summary> ''' A method which will return the encrypted string of this user's MAC address. ''' </summary> ''' <param name="key">OPTIONAL: A key to use when encrypting the data.</param> ''' <returns></returns> ''' <remarks></remarks> Public Shared Function GetEncryptedMAC(Optional ByVal key As String = Nothing) As String Dim retVal As String = Nothing Try Dim mac As String = GetMACAddress() Dim enc As Simple3Des = Nothing If String.IsNullOrEmpty(key) Then enc = New Simple3Des(My.Application.Info.AssemblyName) Else enc = New Simple3Des(key) End If retVal = enc.EncryptData(mac) Catch ex As Exception Throw End Try Return retVal End Function ''' <summary> ''' A method which will return the user's MAC address based on the ''' encrypted string value you give it. ''' </summary> ''' <param name="encMAC">The encrypted MAC address.</param> ''' <param name="key">OPTIONAL: The key which was used when encrypting the data.</param> ''' <returns></returns> ''' <remarks></remarks> Public Shared Function GetDecryptedMAC(ByVal encMAC As String, _ Optional ByVal key As String = Nothing) As String Dim retVal As String = Nothing Try If String.IsNullOrEmpty(encMAC.Trim) Then Throw New ArgumentException("The encrypted MAC address cannot be null or empty.") Else Dim enc As Simple3Des = Nothing If String.IsNullOrEmpty(key) Then enc = New Simple3Des(My.Application.Info.AssemblyName) Else enc = New Simple3Des(key) End If retVal = enc.DecryptData(encMAC) End If Catch ex As Exception Throw End Try Return retVal End Function ''' <summary> ''' A method to return a boolean value indicating whether the ''' MAC address you give it matches this user's MAC address. ''' </summary> ''' <param name="macValue">The MAC address to test.</param> ''' <returns></returns> ''' <remarks></remarks> Public Shared Function TestMAC(ByVal macValue As String) As Boolean Dim retVal As Boolean = False Try If macValue = GetMACAddress() Then retVal = True End If Catch ex As Exception Throw End Try Return retVal End Function ''' <summary> ''' A method which will write (save) the encrypted value of this user's ''' MAC address to the ApplicationData directory on the user's computer. ''' </summary> ''' <param name="key">OPTIONAL: A key to use when encrypting the data.</param> ''' <remarks></remarks> Public Shared Sub WriteEncryptedMAC(Optional ByVal key As String = Nothing) Try If Not My.Computer.FileSystem.DirectoryExists(programDataFolderPath) Then My.Computer.FileSystem.CreateDirectory(programDataFolderPath) End If If Not String.IsNullOrEmpty(key) Then My.Computer.FileSystem.WriteAllText(encMAC_Path, GetEncryptedMAC(key), False) Else My.Computer.FileSystem.WriteAllText(encMAC_Path, GetEncryptedMAC, False) End If Catch ex As Exception Throw End Try End Sub ''' <summary> ''' A method which will return the encrypted string of the user's MAC address ''' which was stored in the user's ApplicationData directory. ''' </summary> ''' <returns></returns> ''' <remarks></remarks> Public Shared Function ReadEncryptedMAC() As String Dim retVal As String = Nothing Try If My.Computer.FileSystem.FileExists(encMAC_Path) Then retVal = My.Computer.FileSystem.ReadAllText(encMAC_Path) End If Catch ex As Exception Throw End Try Return retVal End Function ''' <summary> ''' A method to return a boolean value indicating whether or not the stored ''' encrypted MAC address matches this user's MAC address. ''' </summary> ''' <param name="key">OPTIONAL: The key which was used when encrypting the data.</param> ''' <returns></returns> ''' <remarks></remarks> Public Shared Function TestStoredEncryptedMAC(Optional ByVal key As String = Nothing) As Boolean Dim retVal As Boolean = False Try If My.Computer.FileSystem.FileExists(encMAC_Path) Then Dim enc As String = ReadEncryptedMAC() Dim dec As String = Nothing If Not String.IsNullOrEmpty(key) Then dec = GetDecryptedMAC(enc, key) Else dec = GetDecryptedMAC(enc) End If If dec = GetMACAddress() Then retVal = True End If End If Catch ex As Exception retVal = False End Try Return retVal End Function End Class End Namespace


    I hope it helps. :)


    Please call me Frank :)

    • Marked as answer by Carl Cai Monday, May 5, 2014 5:21 PM
    Saturday, April 26, 2014 6:48 PM
  • hi frank i think you misinterpret if what my purpose to post the whole code of my project, only i need help what im going to do because i dont know how.

    s,

    I've put together an example program which uses my namespace (the namespace is called "Activation") and at the end of this, I'll give you my project folder zipped up so that you can run it for yourself and step through the code, see how it all fits together, etc..

    For this though, I'll show you the code and then some screenshots of me running the program. My example program does nothing useful at all! It's just a TabControl with some TabPages. All user can navigate to TabPage 1 and 2, but they can only navigate to the other TabPages if the program is activated.

    In my example program, I have three forms and the Activation namespace as shown below:

    The code for the three forms are shown on pages of my website:

    Form1.vb

    ActivationInfo.vb

    UserActivationCode.vb

    And the code for the namespace itself is here.

    There are two things (per program that you use this on) that you need to keep up with. They're shown in the code below:

    Public Const activationKey As String = "abracadabra" Public programIdentifier As String = Activation.UserMAC.GetEncryptedMAC


    That top one you want to change per program. I call it "activationKey" but that's not so, not really. It's a key which is used in the encryption routine which takes the user's MAC address and creates an encrypted string from.

    The primary one - the one the user will be shown as the program identifier (or whatever else you want to call it) is your program's name. It's actually the program's AssemblyName, but that's your program's name unless you've changed it.

    Here's how the procedure would work. This is what it looks like when you first turn it on:

    The program hasn't yet been activated so when I try to click on the third TabPage, I get this:

    Now if I click to view the information (the program identifier) which they need to send to you, they'll see this:

    The odd looking string that you see there is the first encrypted string which is actually the user's MAC address. Now they send that number to you. You now use the identically same encryptionKey ("abracadabra" in this one) to create the second encrypted key and you e-mail that back to them. They can now enter that in the other form shown:

    Now I'll test it:

    That form will close and then in the main program (Form1 in mine), they can see that it's activated:

    ...and to verify that, I'll navigate to TabPage3:

    I have the project folder zipped up and uploaded here and I hope this helps. :)


    Please call me Frank :)

    • Marked as answer by Carl Cai Monday, May 5, 2014 5:21 PM
    Tuesday, April 29, 2014 3:35 PM

All replies

  • It might be helpful to include the link to the CodeProject article since we haven no way of knowing what "SecurityManager" is or how it is meant to be used.

    It also isn't clear how you have your application configured to start... is Form5 the startup form?  It looks like you need to check to see if the program is already activated before showing Form5, but where and how you do that will depend on how the application starts.


    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"

    Friday, April 25, 2014 3:29 PM
  • As Reed has already stated - It might be helpful to include the link to the CodeProject article since we have no way of knowing what "SecurityManager" is or how it is meant to be used.

    I would say it is necessary that you include the link or no one here will be able to help you.

    Friday, April 25, 2014 6:14 PM
  • hi all thanks for your time to reply

    heres the link

    http://www.codeproject.com/Articles/28550/Protecting-Your-Software-Using-Simple-Serial-Numbe

    "configuration"

    startup form >>> form5  as a security manager

    after sucessfully activated my main form is show

    but my problem is every time i execute always start on form5

    thats the way i dont know how to permanent activate after sucessfully activated

    Saturday, April 26, 2014 1:29 AM
  • The project directly from the website works exactly as intended as best as I can tell. I have no idea what form5 is so I cannot comment on that.

    you should probably save the activation key once it has been entered successfully. Whatever form is the startup can check this stored value and if correct, load your main form or continue with the startup form and if not, load the "Enter Activation Key" form.

    Look at My.Settings here

    My opinion is also that naming forms with names like Form1, Form2, etc just makes it harder to see where you are. Why not use names like "FormMain", "FormEnterKey", etc ? Same with controls. I have seen projects with 20 or more textboxes named with the default. Bad bad practice in my opinion.

    • Proposed as answer by Cor Ligthert Saturday, April 26, 2014 12:27 PM
    • Marked as answer by Carl Cai Monday, May 5, 2014 5:22 PM
    Saturday, April 26, 2014 5:30 AM
  • s,

    If you're going to use hardware-based activation based on the user's MAC address, maybe give this a try.

    I haven't fully tested it, but I think it should work ok based on my preliminary tests.

    If you want me to explain what's going on (or how to add it to your program and/or how to use it), just let me know:

    Option Strict On Option Explicit On Imports System.Security.Cryptography Imports System.Management Imports System.IO.Path Imports System.Environment Namespace Activation ''' <summary> ''' A class for simple encryption as per MSDN document shown at: ''' http://msdn.microsoft.com/en-us/library/ms172831(v=vs.90).aspx ''' </summary> ''' <remarks></remarks> Public NotInheritable Class Simple3Des Private TripleDes As New TripleDESCryptoServiceProvider Sub New(ByVal key As String) ' Initialize the crypto provider. TripleDes.Key = TruncateHash(key, TripleDes.KeySize \ 8) TripleDes.IV = TruncateHash("", TripleDes.BlockSize \ 8) End Sub Public Function EncryptData(ByVal plaintext As String) _ As String ' Convert the plaintext string to a byte array. Dim plaintextBytes() As Byte = _ System.Text.Encoding.Unicode.GetBytes(plaintext) ' Create the stream. Dim ms As New System.IO.MemoryStream ' Create the encoder to write to the stream. Dim encStream As New CryptoStream(ms, _ TripleDes.CreateEncryptor(), _ System.Security.Cryptography.CryptoStreamMode.Write) ' Use the crypto stream to write the byte array to the stream. encStream.Write(plaintextBytes, 0, plaintextBytes.Length) encStream.FlushFinalBlock() ' Convert the encrypted stream to a printable string. Return Convert.ToBase64String(ms.ToArray) End Function Public Function DecryptData(ByVal encryptedtext As String) _ As String ' Convert the encrypted text string to a byte array. Dim encryptedBytes() As Byte = Convert.FromBase64String(encryptedtext) ' Create the stream. Dim ms As New System.IO.MemoryStream ' Create the decoder to write to the stream. Dim decStream As New CryptoStream(ms, _ TripleDes.CreateDecryptor(), _ System.Security.Cryptography.CryptoStreamMode.Write) ' Use the crypto stream to write the byte array to the stream. decStream.Write(encryptedBytes, 0, encryptedBytes.Length) decStream.FlushFinalBlock() ' Convert the plaintext stream to a string. Return System.Text.Encoding.Unicode.GetString(ms.ToArray) End Function Private Function TruncateHash(ByVal key As String, _ ByVal length As Integer) _ As Byte() Dim sha1 As New SHA1CryptoServiceProvider ' Hash the key. Dim keyBytes() As Byte = _ System.Text.Encoding.Unicode.GetBytes(key) Dim hash() As Byte = sha1.ComputeHash(keyBytes) ' Truncate or pad the hash. ReDim Preserve hash(length - 1) Return hash End Function End Class Public Class UserMAC Private Shared programDataFolderPath As String = _ Combine(GetFolderPath(SpecialFolder.ApplicationData), _ My.Application.Info.AssemblyName) Private Shared encMAC_Path As String = Combine(programDataFolderPath, "encM.h") Public Delegate Function GetMACAddressDelegate() As String ' <summary> ' This will return this user's MAC address as a string. ' </summary> ' <returns></returns> ' <remarks></remarks> Public Shared Function GetMACAddress() As String ' Note that you will need to add a reference to ' System.Management for this to work. Dim retVal As String = Nothing Try Dim mc As New ManagementClass("Win32_NetworkAdapterConfiguration") Dim moc As ManagementObjectCollection = mc.GetInstances() Dim MACAddress As String = "" For Each mo As ManagementObject In moc If MACAddress = "" Then ' Only return MAC Address from first card: If CBool(mo("IPEnabled")) Then MACAddress = mo("MacAddress").ToString() mo.Dispose() Exit For End If End If mo.Dispose() Next moc.Dispose() mc.Dispose() retVal = MACAddress.Replace(":", "") Catch ex As Exception retVal = Nothing End Try Return retVal End Function ''' <summary> ''' A method which will return the encrypted string of this user's MAC address. ''' </summary> ''' <param name="key">OPTIONAL: A key to use when encrypting the data.</param> ''' <returns></returns> ''' <remarks></remarks> Public Shared Function GetEncryptedMAC(Optional ByVal key As String = Nothing) As String Dim retVal As String = Nothing Try Dim mac As String = GetMACAddress() Dim enc As Simple3Des = Nothing If String.IsNullOrEmpty(key) Then enc = New Simple3Des(My.Application.Info.AssemblyName) Else enc = New Simple3Des(key) End If retVal = enc.EncryptData(mac) Catch ex As Exception Throw End Try Return retVal End Function ''' <summary> ''' A method which will return the user's MAC address based on the ''' encrypted string value you give it. ''' </summary> ''' <param name="encMAC">The encrypted MAC address.</param> ''' <param name="key">OPTIONAL: The key which was used when encrypting the data.</param> ''' <returns></returns> ''' <remarks></remarks> Public Shared Function GetDecryptedMAC(ByVal encMAC As String, _ Optional ByVal key As String = Nothing) As String Dim retVal As String = Nothing Try If String.IsNullOrEmpty(encMAC.Trim) Then Throw New ArgumentException("The encrypted MAC address cannot be null or empty.") Else Dim enc As Simple3Des = Nothing If String.IsNullOrEmpty(key) Then enc = New Simple3Des(My.Application.Info.AssemblyName) Else enc = New Simple3Des(key) End If retVal = enc.DecryptData(encMAC) End If Catch ex As Exception Throw End Try Return retVal End Function ''' <summary> ''' A method to return a boolean value indicating whether the ''' MAC address you give it matches this user's MAC address. ''' </summary> ''' <param name="macValue">The MAC address to test.</param> ''' <returns></returns> ''' <remarks></remarks> Public Shared Function TestMAC(ByVal macValue As String) As Boolean Dim retVal As Boolean = False Try If macValue = GetMACAddress() Then retVal = True End If Catch ex As Exception Throw End Try Return retVal End Function ''' <summary> ''' A method which will write (save) the encrypted value of this user's ''' MAC address to the ApplicationData directory on the user's computer. ''' </summary> ''' <param name="key">OPTIONAL: A key to use when encrypting the data.</param> ''' <remarks></remarks> Public Shared Sub WriteEncryptedMAC(Optional ByVal key As String = Nothing) Try If Not My.Computer.FileSystem.DirectoryExists(programDataFolderPath) Then My.Computer.FileSystem.CreateDirectory(programDataFolderPath) End If If Not String.IsNullOrEmpty(key) Then My.Computer.FileSystem.WriteAllText(encMAC_Path, GetEncryptedMAC(key), False) Else My.Computer.FileSystem.WriteAllText(encMAC_Path, GetEncryptedMAC, False) End If Catch ex As Exception Throw End Try End Sub ''' <summary> ''' A method which will return the encrypted string of the user's MAC address ''' which was stored in the user's ApplicationData directory. ''' </summary> ''' <returns></returns> ''' <remarks></remarks> Public Shared Function ReadEncryptedMAC() As String Dim retVal As String = Nothing Try If My.Computer.FileSystem.FileExists(encMAC_Path) Then retVal = My.Computer.FileSystem.ReadAllText(encMAC_Path) End If Catch ex As Exception Throw End Try Return retVal End Function ''' <summary> ''' A method to return a boolean value indicating whether or not the stored ''' encrypted MAC address matches this user's MAC address. ''' </summary> ''' <param name="key">OPTIONAL: The key which was used when encrypting the data.</param> ''' <returns></returns> ''' <remarks></remarks> Public Shared Function TestStoredEncryptedMAC(Optional ByVal key As String = Nothing) As Boolean Dim retVal As Boolean = False Try If My.Computer.FileSystem.FileExists(encMAC_Path) Then Dim enc As String = ReadEncryptedMAC() Dim dec As String = Nothing If Not String.IsNullOrEmpty(key) Then dec = GetDecryptedMAC(enc, key) Else dec = GetDecryptedMAC(enc) End If If dec = GetMACAddress() Then retVal = True End If End If Catch ex As Exception retVal = False End Try Return retVal End Function End Class End Namespace


    I hope it helps. :)


    Please call me Frank :)

    • Marked as answer by Carl Cai Monday, May 5, 2014 5:21 PM
    Saturday, April 26, 2014 6:48 PM
  • hi frank thanks for your time to reply my question

    this is my "security manager.vb"

    Imports System.Management
    Class SecurityManager
        Public Function GetSerial() As Long
            Dim HWID As String = String.Empty
            Dim mcl As New ManagementClass("win32_processor")
            Dim MOBC As ManagementObjectCollection = mcl.GetInstances()

            For Each mob As ManagementObject In MOBC
                If HWID = "" Then
                    HWID = mob.Properties("processorID").Value.ToString()
                    Exit For
                End If

            Next

            Dim sum As Long = 0
            Dim index As Integer = 1
            For Each ch As Char In HWID
                If Char.IsDigit(ch) Then
                    sum += sum + Integer.Parse(ch) * (index * 2)
                ElseIf Char.IsLetter(ch) Then
                    Select Case ch.ToString.ToUpper
                        Case "A"
                            sum += sum + 10 * (index * 2)
                        Case "B"
                            sum += sum + 11 * (index * 6)
                        Case "C"
                            sum += sum + 12 * (index * 2)
                        Case "D"
                            sum += sum + 13 * (index * 5)
                        Case "E"
                            sum += sum + 14 * (index * 2)
                        Case "F"
                            sum += sum + 15 * (index * 4)
                    End Select
                End If

                index += 1
            Next

            Return sum
        End Function

        Public Function CheckKey(ByVal key As Long) As Boolean
            Dim x As Long = GetSerial()
            Dim y As Long = x * x + 53 / x + 1013 * (x / 20)
            Return y = key
        End Function
    End Class

    ******************************************************

    this my form5

                          

    Public Class Form5


        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Dim serial As Long
            Dim sm As New SecurityManager
            serial = sm.GetSerial
            txtSerial.Text = serial
        End Sub
        Private Sub btnActivate_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnActivate.Click
            Dim key As Long
            If Not Long.TryParse(txtKey.Text, key) Then
                MessageBox.Show("Invalid activation key")
                Exit Sub
            End If

            Dim sm As New SecurityManager
            If sm.CheckKey(key) Then
                MessageBox.Show("Activation was successful")
            Else
                MessageBox.Show("Activation was unsuccessful")
                Me.Hide()
            End If
        End Sub

    Sunday, April 27, 2014 8:42 AM
  • whole code work fine but only problem is when

    ("Activation was successful")form5 return to startup form if i execute again of my application "Timer"

    i want if Activation was successful "Timer" is Startup


     

    Sunday, April 27, 2014 9:28 AM
  • s,

    Thanks for the code, but I don't need it. ;-)


    Please call me Frank :)

    Sunday, April 27, 2014 1:26 PM
  • s,

    Thanks for the code, but I don't need it. ;-)


    Please call me Frank :)


    hi frank i think you misinterpret if what my purpose to post the whole code of my project, only i need help what im going to do because i dont know how.
    Monday, April 28, 2014 10:40 PM
  • hi

    my form5 is Regestration form this is my startup form, and my form1 is a Timer, when i input the right activation based on getserial from security manager msgbox show "activation sucessful" its work perfectly,

    i want my form1 a Timer show first after "activation sucessful".

    Monday, April 28, 2014 10:57 PM
  • hi frank i think you misinterpret if what my purpose to post the whole code of my project, only i need help what im going to do because i dont know how.

    I realize that - I was being facetious.

    I'll show you tomorrow with an example program.


    Please call me Frank :)

    Monday, April 28, 2014 11:45 PM
  • hi frank i think you misinterpret if what my purpose to post the whole code of my project, only i need help what im going to do because i dont know how.

    s,

    I've put together an example program which uses my namespace (the namespace is called "Activation") and at the end of this, I'll give you my project folder zipped up so that you can run it for yourself and step through the code, see how it all fits together, etc..

    For this though, I'll show you the code and then some screenshots of me running the program. My example program does nothing useful at all! It's just a TabControl with some TabPages. All user can navigate to TabPage 1 and 2, but they can only navigate to the other TabPages if the program is activated.

    In my example program, I have three forms and the Activation namespace as shown below:

    The code for the three forms are shown on pages of my website:

    Form1.vb

    ActivationInfo.vb

    UserActivationCode.vb

    And the code for the namespace itself is here.

    There are two things (per program that you use this on) that you need to keep up with. They're shown in the code below:

    Public Const activationKey As String = "abracadabra" Public programIdentifier As String = Activation.UserMAC.GetEncryptedMAC


    That top one you want to change per program. I call it "activationKey" but that's not so, not really. It's a key which is used in the encryption routine which takes the user's MAC address and creates an encrypted string from.

    The primary one - the one the user will be shown as the program identifier (or whatever else you want to call it) is your program's name. It's actually the program's AssemblyName, but that's your program's name unless you've changed it.

    Here's how the procedure would work. This is what it looks like when you first turn it on:

    The program hasn't yet been activated so when I try to click on the third TabPage, I get this:

    Now if I click to view the information (the program identifier) which they need to send to you, they'll see this:

    The odd looking string that you see there is the first encrypted string which is actually the user's MAC address. Now they send that number to you. You now use the identically same encryptionKey ("abracadabra" in this one) to create the second encrypted key and you e-mail that back to them. They can now enter that in the other form shown:

    Now I'll test it:

    That form will close and then in the main program (Form1 in mine), they can see that it's activated:

    ...and to verify that, I'll navigate to TabPage3:

    I have the project folder zipped up and uploaded here and I hope this helps. :)


    Please call me Frank :)

    • Marked as answer by Carl Cai Monday, May 5, 2014 5:21 PM
    Tuesday, April 29, 2014 3:35 PM
  • hi frank many thanks for your effort this is very helpful to me

    but i dont know how to make key generator using your sample project

    and how did you get the activation code?

    Thursday, May 22, 2014 3:02 AM
  • hi frank many thanks for your effort this is very helpful to me

    but i dont know how to make key generator using your sample project

    and how did you get the activation code?

    Their activation code is their own MAC address, encrypted (two different encryptions).

    Please re-read what I wrote - I thought it was pretty clear.


    Please call me Frank :)

    • Marked as answer by s.pac Thursday, May 22, 2014 1:43 PM
    Thursday, May 22, 2014 12:27 PM
  • hi frank thanks for your reply

    i got it, many thanks

    one other question

    how to replace MAC to BIOS,Mainboard,HDD ID, and encrypt it

    i need a hardware lock.

    Thursday, May 22, 2014 1:46 PM
  • hi frank thanks for your reply

    i got it, many thanks

    one other question

    how to replace MAC to BIOS,Mainboard,HDD ID, and encrypt it

    i need a hardware lock.

    You can use WMI for that, but how about do this:

    Ask that specific question as a new question. I'd have to go hunt down how to get that data (and I honestly just don't have time right now), but others here know it pretty well and can give you an answer pretty quickly.


    Please call me Frank :)

    Thursday, May 22, 2014 2:29 PM