none
Serial Key for Software Question RRS feed

  • Question

  • I created a program and I would like to protect it with a serial key. I tried using the following, but after I run it I would like for the program to run and the regform not to open again.

    Public Class RegForm
        Private Sub RegForm_Load(sender As Object, e As EventArgs) Handles Me.Load
            
            If My.Settings.Register = False Then
                Me.TextBox1.Focus()
                Form2.Hide()
    
    
            End If
           
    
        End Sub
    
    
        Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
            If TextBox1.Text.Length = 4 Then
                TextBox2.Text = ""
                TextBox2.Focus()
            End If
        End Sub
    
        Private Sub TextBox2_TextChanged(sender As Object, e As EventArgs) Handles TextBox2.TextChanged
            If TextBox2.Text.Length = 4 Then
                TextBox3.Text = ""
                TextBox3.Focus()
            End If
        End Sub
    
        Private Sub TextBox3_TextChanged(sender As Object, e As EventArgs) Handles TextBox3.TextChanged
            If TextBox3.Text.Length = 4 Then
                TextBox4.Text = ""
                TextBox4.Focus()
            End If
        End Sub
    
        Private Sub TextBox4_TextChanged(sender As Object, e As EventArgs) Handles TextBox4.TextChanged
            If TextBox4.Text.Length = 4 Then
                Button1.Focus()
            End If
        End Sub
    
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            If TextBox1.Text + TextBox2.Text + TextBox3.Text + TextBox4.Text = "9182736453642019" Then
                MsgBox("The Serial Number is Correct", , Title:="Software Serial Number Verification")
                My.Settings.Register = True
                Form2.Show()
                Me.Close()
    
    
    
    
            Else : MsgBox("Please Check the Serial Number and Try Again", Title:="Software Serial Number Verification", Buttons:=MsgBoxStyle.OkOnly)
    
    
            End If
        End Sub
    End Class

    Sunday, August 17, 2014 9:27 PM

Answers

  • I created a program and I would like to protect it with a serial key. I tried using the following, but after I run it I would like for the program to run and the regform not to open again.

    Public Class RegForm
        Private Sub RegForm_Load(sender As Object, e As EventArgs) Handles Me.Load
            
            If My.Settings.Register = False Then
                Me.TextBox1.Focus()
                Form2.Hide()
    
    
            End If
           
    
        End Sub
    
    
        Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
            If TextBox1.Text.Length = 4 Then
                TextBox2.Text = ""
                TextBox2.Focus()
            End If
        End Sub
    
        Private Sub TextBox2_TextChanged(sender As Object, e As EventArgs) Handles TextBox2.TextChanged
            If TextBox2.Text.Length = 4 Then
                TextBox3.Text = ""
                TextBox3.Focus()
            End If
        End Sub
    
        Private Sub TextBox3_TextChanged(sender As Object, e As EventArgs) Handles TextBox3.TextChanged
            If TextBox3.Text.Length = 4 Then
                TextBox4.Text = ""
                TextBox4.Focus()
            End If
        End Sub
    
        Private Sub TextBox4_TextChanged(sender As Object, e As EventArgs) Handles TextBox4.TextChanged
            If TextBox4.Text.Length = 4 Then
                Button1.Focus()
            End If
        End Sub
    
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            If TextBox1.Text + TextBox2.Text + TextBox3.Text + TextBox4.Text = "9182736453642019" Then
                MsgBox("The Serial Number is Correct", , Title:="Software Serial Number Verification")
                My.Settings.Register = True
                Form2.Show()
                Me.Close()
    
    
    
    
            Else : MsgBox("Please Check the Serial Number and Try Again", Title:="Software Serial Number Verification", Buttons:=MsgBoxStyle.OkOnly)
    
    
            End If
        End Sub
    End Class

    In the old days you used to buy all software pretty much on a CD that had a validation key. But you could give that CD to any number of people who could install it on their system.

    I believe nowadays more and more software requires you to get a registration or something via the net even if you install it with a key as it will not run without whatever the registration provides or something. But I'm not 100% sure.

    So on a thread about a year or so ago I provided assistance to Pete Bambenek Auto LLC / Owner for a rather large program he's writing to provide images of electrical wiring diagrams and some sort of .PDF files with encryption so all those files can be stored on a customers PC encrypted and displayed decrypted.

    I came up with a method that gets the BIOS hardware ID of the PC the customer installs the software on. If the customer only purchases a single license then they can only install the software on a single PC.

    Petes program uses a validation key provided internally in the app. When the app is installed it will not "run" the main app but will display a dialog which shows the apps key in a textbox. Another key, the customer key, is created by processing the BIOS hardware ID of the PC the app is installed on into a key using code and displayed in the next textbox down. A third textbox requires the customer to either go to Petes database online and I guess create an account in order to get a verification key or something or they can call Pete to get one I suppose.

    So the app will not "run" until the verification key is entered into the dialog. Without the verification key or with an improper verification key the app shuts down after the dialog closes and the main form of the app is never displayed.

    Also the verification key provided either online or via telephone or email perhaps will not work if the app is installed on a different PC as the new PC's BIOS hardware ID is different than the one the verification key is for.

    When the app is first installed it encrypts its internal verification key and key created by the BIOS hardware ID as well as the verification key Pete will provide the customer to the user.Config file for the user installing the app on the PC.

    Well how can it already have the verification key Pete is supposed to provide the customer? Because the code Pete has to create a verification key for a customer from the customers apps internal verification key and key created from the BIOS hardware ID is in the app also. So the app creates it and stores it encrypted. When Pete gives the customer their verification key and the customer types it in the dialogs textbox the app checks that against what is already stored encrypted. If the two match then the app will run.

    And for any user on that same PC the same verification key from Pete, for that PC, must be used for the first time that user launches the app or the app for that user will not run.

    This means if a customer buys two licenses for the app it will only ever run on the first two PC's they install it on. As Pete knows how many licenses they purchased for the app and how many verification keys he has provided out for that apps internal verification key and key created from the BIOS hardware ID.

    So lets say a customers PC "dies" and they need to install a copy of that app on another PC. Well it will not work until they get a new verification key for the new PC. So Pete I suppose has taken that into account and will provide the customer a new verification key for the customer after some kind of communication takes place to find out why they want a new verification key when they already have two for a two license app and haven't purchased a third license.

    What you're trying to do I'm not certain. But if it's to protect your app there's probably a lot of things you may need to learn before writing code to do something that may do nothing at all.

    Plus My.Settings are in a user.config file. An unencrypted XML file. The file can be edited and any value changed at anytime. Which is why Pete uses encryption to encrypt thos values. Therefore the customer does not know what the actual values are. And trying to copy and paste them into a user config file on another machine will not make the app work on a different machine.

    You can download the project for the app here Application Registry Security example and for the key generator for the apps internal key and for the authorization key maker there is code displayed on the page of the link since I didn't know how, at the time, to add three projects to the code gallery for a single addition.


    La vida loca




    • Edited by Mr. Monkeyboy Monday, August 18, 2014 4:18 AM
    • Marked as answer by VBShaper Monday, August 18, 2014 10:39 AM
    Monday, August 18, 2014 4:06 AM

All replies

  • VBS,

    I'd suggest all sorts of things looking at your code there. Start with this though: At the top of your form (all of your forms if more than one), put the following:

    Option Strict On
    Option Explicit On
    Option Infer Off

    You'll see VB showing you several compile errors and you need to work your way through those. I'd also suggest naming your controls to something meaningful.

    *****

    Once you get all of that, then we can talk about some of the more specifics of your question including where the serial numbers are stored (how would it know a valid one from an invalid one?), how are you going to convey that serial number to the user and what would prevent them from sharing that key with others, and so on.

    This is a pretty deep topic actually, so it's hard to summarize anything about it in a single question like this.

    ***** EDIT *****

    In looking more closely, it may not show compile errors. I saw the "+" with TextBoxes and got confused (dotNET can equally get confused though).

    For string concatenation, use the ampersand, not the "+" character.


    Still lost in code, just at a little higher level.

    :-)


    Sunday, August 17, 2014 10:40 PM
  • I did not find any errors?
    Sunday, August 17, 2014 11:52 PM
  • I did not find any errors?

    Like I said in my edit, that was my mistake when seeing the plus signs rather than the ampersand.

    *****

    It looks like everyone will have the same serial number? Is this just for a test I'm guessing?

    I'd encourage you to set up a form which you'll show modally and pass back a return value. That can be done several ways, but that way the other form has to be dismissed before the user can continue.

    For example, if you have another form named Form2.vb (and if it's set up the way I'm thinking I'd do it), in Form1 you might call it inside a method like this:

    Using f2 As New Form2
        f2.ShowDialog()

        If Not f2.userCancel
            If f2.userPass
                ' Now you know they've been validated.
            End If
        End If
    End Using

    This assumes you have the properties or variables that I just described set up for these, but my point is that by showing it modally, the user cannot access the form of the calling code until Form2 has been dismissed. If they simply "X" close it, then "userCancel" is true and you take appropriate action. That might be closing the program or repeating the dialog or whatever you want to do at that point.

    *****

    If you want to let's talk about alternates for real validation -- then this will get to be a long thread.

    ;-)


    Still lost in code, just at a little higher level.

    :-)

    Sunday, August 17, 2014 11:59 PM
  • I created a program and I would like to protect it with a serial key. I tried using the following, but after I run it I would like for the program to run and the regform not to open again.

    Public Class RegForm
        Private Sub RegForm_Load(sender As Object, e As EventArgs) Handles Me.Load
            
            If My.Settings.Register = False Then
                Me.TextBox1.Focus()
                Form2.Hide()
    
    
            End If
           
    
        End Sub
    
    
        Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
            If TextBox1.Text.Length = 4 Then
                TextBox2.Text = ""
                TextBox2.Focus()
            End If
        End Sub
    
        Private Sub TextBox2_TextChanged(sender As Object, e As EventArgs) Handles TextBox2.TextChanged
            If TextBox2.Text.Length = 4 Then
                TextBox3.Text = ""
                TextBox3.Focus()
            End If
        End Sub
    
        Private Sub TextBox3_TextChanged(sender As Object, e As EventArgs) Handles TextBox3.TextChanged
            If TextBox3.Text.Length = 4 Then
                TextBox4.Text = ""
                TextBox4.Focus()
            End If
        End Sub
    
        Private Sub TextBox4_TextChanged(sender As Object, e As EventArgs) Handles TextBox4.TextChanged
            If TextBox4.Text.Length = 4 Then
                Button1.Focus()
            End If
        End Sub
    
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            If TextBox1.Text + TextBox2.Text + TextBox3.Text + TextBox4.Text = "9182736453642019" Then
                MsgBox("The Serial Number is Correct", , Title:="Software Serial Number Verification")
                My.Settings.Register = True
                Form2.Show()
                Me.Close()
    
    
    
    
            Else : MsgBox("Please Check the Serial Number and Try Again", Title:="Software Serial Number Verification", Buttons:=MsgBoxStyle.OkOnly)
    
    
            End If
        End Sub
    End Class

    In the old days you used to buy all software pretty much on a CD that had a validation key. But you could give that CD to any number of people who could install it on their system.

    I believe nowadays more and more software requires you to get a registration or something via the net even if you install it with a key as it will not run without whatever the registration provides or something. But I'm not 100% sure.

    So on a thread about a year or so ago I provided assistance to Pete Bambenek Auto LLC / Owner for a rather large program he's writing to provide images of electrical wiring diagrams and some sort of .PDF files with encryption so all those files can be stored on a customers PC encrypted and displayed decrypted.

    I came up with a method that gets the BIOS hardware ID of the PC the customer installs the software on. If the customer only purchases a single license then they can only install the software on a single PC.

    Petes program uses a validation key provided internally in the app. When the app is installed it will not "run" the main app but will display a dialog which shows the apps key in a textbox. Another key, the customer key, is created by processing the BIOS hardware ID of the PC the app is installed on into a key using code and displayed in the next textbox down. A third textbox requires the customer to either go to Petes database online and I guess create an account in order to get a verification key or something or they can call Pete to get one I suppose.

    So the app will not "run" until the verification key is entered into the dialog. Without the verification key or with an improper verification key the app shuts down after the dialog closes and the main form of the app is never displayed.

    Also the verification key provided either online or via telephone or email perhaps will not work if the app is installed on a different PC as the new PC's BIOS hardware ID is different than the one the verification key is for.

    When the app is first installed it encrypts its internal verification key and key created by the BIOS hardware ID as well as the verification key Pete will provide the customer to the user.Config file for the user installing the app on the PC.

    Well how can it already have the verification key Pete is supposed to provide the customer? Because the code Pete has to create a verification key for a customer from the customers apps internal verification key and key created from the BIOS hardware ID is in the app also. So the app creates it and stores it encrypted. When Pete gives the customer their verification key and the customer types it in the dialogs textbox the app checks that against what is already stored encrypted. If the two match then the app will run.

    And for any user on that same PC the same verification key from Pete, for that PC, must be used for the first time that user launches the app or the app for that user will not run.

    This means if a customer buys two licenses for the app it will only ever run on the first two PC's they install it on. As Pete knows how many licenses they purchased for the app and how many verification keys he has provided out for that apps internal verification key and key created from the BIOS hardware ID.

    So lets say a customers PC "dies" and they need to install a copy of that app on another PC. Well it will not work until they get a new verification key for the new PC. So Pete I suppose has taken that into account and will provide the customer a new verification key for the customer after some kind of communication takes place to find out why they want a new verification key when they already have two for a two license app and haven't purchased a third license.

    What you're trying to do I'm not certain. But if it's to protect your app there's probably a lot of things you may need to learn before writing code to do something that may do nothing at all.

    Plus My.Settings are in a user.config file. An unencrypted XML file. The file can be edited and any value changed at anytime. Which is why Pete uses encryption to encrypt thos values. Therefore the customer does not know what the actual values are. And trying to copy and paste them into a user config file on another machine will not make the app work on a different machine.

    You can download the project for the app here Application Registry Security example and for the key generator for the apps internal key and for the authorization key maker there is code displayed on the page of the link since I didn't know how, at the time, to add three projects to the code gallery for a single addition.


    La vida loca




    • Edited by Mr. Monkeyboy Monday, August 18, 2014 4:18 AM
    • Marked as answer by VBShaper Monday, August 18, 2014 10:39 AM
    Monday, August 18, 2014 4:06 AM
  • Thank you Mr. Monkeyboy,

    I will look at the project. I think I have to rethink how I create the key code.

    Monday, August 18, 2014 10:39 AM
  • Thank you Mr. Monkeyboy,

    I will look at the project. I think I have to rethink how I create the key code.

    You're welcome. And that project was done awhile ago.

    So I'm fairly certain I would do things differently within it for creating a key from the BIOS hardware ID as well as creating a key from "mixing" the apps hardcoded key and the key created from the BIOS hardware ID. And incorporate that code in the authorization key maker.


    La vida loca

    Monday, August 18, 2014 2:04 PM
  • Mr. Monkeyboy - just an FYI re the code on MSDN

    the WMI call to get the Serial Number fails here

    This code:

            Dim query As New SelectQuery("Win32_bios")
            Dim search As New ManagementObjectSearcher(query)
            Dim info As ManagementObject
            Dim BiosInfo As String = ""
            For Each info In search.Get()
                BiosInfo &= info("SerialNumber").ToString & ","
            Next
            TextBox1.Text = BiosInfo

    Returns "System Serial Number"

    While this code:

            Dim StrBIOSSerial As String = String.Empty
            Dim query As New SelectQuery("Win32_BaseBoard")
            Dim search As New ManagementObjectSearcher(query)
            Dim info As ManagementObject
            Try
                For Each info In search.Get()
                    StrBIOSSerial &= info("SerialNumber").ToString()
                Next
            Catch ex As Exception
                StrBIOSSerial = "Error retreiving Amount of Memory"
            End Try
            TextBox1.Text = StrBIOSSerial

    Returns : 101378530000383

    Monday, August 18, 2014 5:41 PM