Product Key Manager *Update*

Heres your chance to share your own tutorials with the community. Just post them on here. If your lucky they may even be posted on the main site.
38 posts Page 1 of 4
User avatar
CodenStuff
Site Admin
Site Admin
Posts: 4389
Joined: Tue Aug 04, 2009 1:47 am

Product Key Manager *Update*
CodenStuff
Hello,

Image

If you have used the Product Key Management System tutorial then I have an update for you. This update will give you the ability to add personal information to a members account like:

Name
Email address
Home address
Software purchased
Date of purchase


You could use this information to send emails to people who have purchased your software informing them of new available software and things like that. You can decide how to use the information but its a good way of keeping detailed records of those that purchase your product keys.

This isnt a big code change so it should only take a couple of minutes to add to your existing code. First open your key managers main form and add 6 new textbox controls and 1 button control. It would be best to stretch your form out a bit to make room for these and those controls will be used as follows:
*this assumes that you followed the original tutorial*

TextBox5 - Place this anywhere on your form and make it "invisible"
TextBox6 - Used to store members name
TextBox7 - Used to store members email
Textbox8 - Make this 'MultiLine' ...Used to store members Address
TextBox9 - Used to store software purchased
TextBox10 - Used to store date of key purchase
Button4 - Used to save the member information

Arrange those controls on your form however you like and then go into code-view and add/change the following:

Find this:
Code: Select all
MsgBox("E-mail successfully sent to:" + TextBox1.Text)
        ComboBox2.Items.Add(TextBox2.Text)
        My.Computer.FileSystem.WriteAllText(Application.StartupPath & "\" + TextBox2.Text + ".usr", trialtime, False)
        My.Computer.FileSystem.WriteAllText(Application.StartupPath + "\" + TextBox2.Text + ".act", TextBox3.Text, True)
        My.Computer.Network.UploadFile(Application.StartupPath + "\" + TextBox2.Text + ".act", "ftp://www.YOURSITE.com/" + TextBox2.Text + ".act", "USERNAME", "PASSWORD", True, 10, FileIO.UICancelOption.DoNothing)
        If My.Computer.FileSystem.FileExists(Application.StartupPath + "\" + TextBox2.Text + ".act") Then
            My.Computer.FileSystem.DeleteFile(Application.StartupPath + "\" + TextBox2.Text + ".act", FileIO.UIOption.OnlyErrorDialogs, FileIO.RecycleOption.DeletePermanently)
        End If
Replace it with:
Code: Select all
MsgBox("E-mail successfully sent to:" + TextBox1.Text)
        ComboBox2.Items.Add(TextBox2.Text)
        My.Computer.FileSystem.WriteAllText(Application.StartupPath & "\" + TextBox2.Text + ".usr", trialtime + "|" + "|" + TextBox1.Text + "|" + "|" + ComboBox1.Text + "|" + Date.Now + " ", False)
        My.Computer.FileSystem.WriteAllText(Application.StartupPath + "\" + TextBox2.Text + ".act", TextBox3.Text, True)
        My.Computer.Network.UploadFile(Application.StartupPath + "\" + TextBox2.Text + ".act", "ftp://www.YOURSITE.com/" + TextBox2.Text + ".act", "USERNAME", "PASSWORD", True, 10, FileIO.UICancelOption.DoNothing)
        If My.Computer.FileSystem.FileExists(Application.StartupPath + "\" + TextBox2.Text + ".act") Then
            My.Computer.FileSystem.DeleteFile(Application.StartupPath + "\" + TextBox2.Text + ".act", FileIO.UIOption.OnlyErrorDialogs, FileIO.RecycleOption.DeletePermanently)
        End If
Find this Sub:
Code: Select all
Private Sub ComboBox2_SelectedIndexChanged
And replace all the code within it with this:
Code: Select all
Dim currentdatetime As Date = Now
        Try
            If My.Computer.FileSystem.FileExists(Application.StartupPath & "\" + ComboBox2.Text + ".usr") Then
                Using sr As New IO.StreamReader(Application.StartupPath & "\" + ComboBox2.Text + ".usr")
                    TextBox5.Text = sr.ReadToEnd
                    TextBox4.Text = TextBox5.Text.Split("|"c)(0)
                    TextBox6.Text = TextBox5.Text.Split("|"c)(1)
                    TextBox7.Text = TextBox5.Text.Split("|"c)(2)
                    TextBox8.Text = TextBox5.Text.Split("|"c)(3)
                    TextBox9.Text = TextBox5.Text.Split("|"c)(4)
                    TextBox10.Text = TextBox5.Text.Split("|"c)(5)
                End Using
            End If
            Dim url As String = "http://www.YOURSITE.com/" + ComboBox2.Text + ".act"
            Dim pageRequest As HttpWebRequest = CType(WebRequest.Create(url), HttpWebRequest)
            Dim pageResponse As WebResponse = pageRequest.GetResponse()
            Dim page As String = ""
            Using r As New StreamReader(pageResponse.GetResponseStream())
                page = r.ReadToEnd()
            End Using
            If page = "****KEY-USED********KEY-USED****" Then
                Label7.ForeColor = Color.Green
                Label7.Text = "Activated"
            ElseIf page = "****DE-ACTIVATED****" Then
                Label7.ForeColor = Color.Red
                Label7.Text = "De-Activated"
            Else
                Label7.ForeColor = Color.Red
                Label7.Text = "Not Activated"
                If (currentdatetime > TextBox4.Text) Then
                    Button3.Enabled = True
                    Label7.Text = "Out of date!"
                End If
            End If
            Button5.Enabled = True
        Catch ex As Exception

        End Try
Find this Sub:
Code: Select all
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
And again replace all the code within it with this:
Code: Select all
My.Computer.FileSystem.WriteAllText(Application.StartupPath + "\" + ComboBox2.Text + ".act", "****DE-ACTIVATED****", True)
        My.Computer.Network.UploadFile(Application.StartupPath + "\" + ComboBox2.Text + ".act", "ftp://www.YOURSITE.com/" + ComboBox2.Text + ".act", "USERNAME", "PASSWORD", True, 10, FileIO.UICancelOption.DoNothing)
        If My.Computer.FileSystem.FileExists(Application.StartupPath + "\" + ComboBox2.Text + ".act") Then
            My.Computer.FileSystem.DeleteFile(Application.StartupPath + "\" + ComboBox2.Text + ".act", FileIO.UIOption.OnlyErrorDialogs, FileIO.RecycleOption.DeletePermanently)
        End If
        If My.Computer.FileSystem.FileExists(Application.StartupPath + "\" + ComboBox2.Text + ".usr") Then
            My.Computer.FileSystem.DeleteFile(Application.StartupPath + "\" + ComboBox2.Text + ".usr", FileIO.UIOption.OnlyErrorDialogs, FileIO.RecycleOption.DeletePermanently)
        End If
        'ComboBox2.Items.Remove(ComboBox2.Text)
        If My.Computer.FileSystem.FileExists(Application.StartupPath & "\Accounts.act") Then
            My.Computer.FileSystem.DeleteFile(Application.StartupPath & "\Accounts.act", FileIO.UIOption.OnlyErrorDialogs, FileIO.RecycleOption.DeletePermanently)
        End If
        With ComboBox2
            Dim i As Integer
            Dim s As String = ""
            For i = 0 To .Items.Count - 1
                s += .Items(i).ToString & vbNewLine
            Next

            My.Computer.FileSystem.WriteAllText(Application.StartupPath & "\Accounts.act", s, False)
        End With
        My.Computer.FileSystem.WriteAllText(Application.StartupPath & "\" + ComboBox2.Text + ".usr", "No longer in use" + "|" + TextBox6.Text + "|" + TextBox7.Text + "|" + TextBox8.Text + "|" + TextBox9.Text + "|" + TextBox10.Text + " ", False)
        Button3.Enabled = False
        MsgBox("Account has been deactivated!")
Use this code for the Button4 click event:
Code: Select all
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        If My.Computer.FileSystem.FileExists(Application.StartupPath + "\" + ComboBox2.Text + ".usr") Then
            My.Computer.FileSystem.DeleteFile(Application.StartupPath + "\" + ComboBox2.Text + ".usr", FileIO.UIOption.OnlyErrorDialogs, FileIO.RecycleOption.DeletePermanently)
        End If
        My.Computer.FileSystem.WriteAllText(Application.StartupPath & "\" + ComboBox2.Text + ".usr", TextBox4.Text + "|" + TextBox6.Text + "|" + TextBox7.Text + "|" + TextBox8.Text + "|" + TextBox9.Text + "|" + TextBox10.Text + " ", False)

    End Sub
And thats all you need to do :D .

As ProductKeyManager version 2.0 is available in the VIP section I am now making available version 1.5 for public download. This version includes this user account information update tutorial within the code
:
Download:
SerialManagerv105.zip
Happy coding! cooll;
You do not have the required permissions to view the files attached to this post.
Welcome to CodenStuff.com Learn Code, Love Code. Thank you for being a member of the community.
User avatar
CodenStuff
Site Admin
Site Admin
Posts: 4389
Joined: Tue Aug 04, 2009 1:47 am

Second Update - Force Trial Mode
CodenStuff
Hello,

OK I have made another update as requested by a member of codenstuff.com and this one is for both the activation "add-on" and the product key manager application. It gives you the ability to force a users software back into trial mode, this could be used for example if a users payment is reversed or they are abusing your software or you want to do a monthly/yearly subscribtion type of thing.


OK this first part is for the "add-on" that you need to use within your application.

In the navigation menu click "Project > YourApp Properties" and then click the "Settings" tab on the left hand side.

Now we need to enter a new setting in here so ill tell you the name of the setting and its value which you need to enter

keycheck - Value = nouser

OK close that and save the settings.

Now in your form_load event you need to replace the original "add-on" code with this:
Code: Select all
 Try
            Dim url As String = "http://www.YOURWEBSITE.com/" + Convert.ToString(My.Settings.keycheck) + ".act"
            Dim pageRequest As HttpWebRequest = CType(WebRequest.Create(url), HttpWebRequest)
            Dim pageResponse As WebResponse = pageRequest.GetResponse()
            Dim page As String = ""
            Using r As New StreamReader(pageResponse.GetResponseStream())
                page = r.ReadToEnd()
            End Using

            'END SERIALS
            If Convert.ToString(My.Settings.activated) = "1" Then
                If page = "***KEY-DESTROYED***" Then
                    Dim trialtime As Date = Now
                    trialtime = trialtime.AddDays(30) 'SET THIS TO HOWEVER MANY DAYS YOU WANT THE TRIAL TO RUN FOR
                    My.Settings.trialcode = trialtime
                    My.Settings.apptrial = "1"
                    My.Settings.activated = "0"
                    My.Settings.Save()
                    MsgBox("Your key is no longer valid.  Please contact the software vender.")
                    Application.Restart()

                End If
            End If
        Catch ex As Exception

        End Try
        Dim tcode = Convert.ToString(My.Settings.activated)
        If (tcode = "1") Then
            Button1.Visible = False
            Me.Text = "My Software Full Version"
        Else
            isittrial()
            Me.Text = "My Software 30-Day Trial"
        End If
You will notice that in the code above I change the applications title text to reflect wether it is activated or in trial mode. You can change these or remove them if you wish, I just used "My Software Full Version" if its activated and "My Software 30-Day Trial" is its in trial mode.

OK thats the "add-on" code update completed so now you need to open up your product key manager application.
*This assumes you are using the code/layout from the original tutorial*

Add a new button control to your form and label it something like "Delete Key" and then use the following code inside that buttons click event:
Code: Select all
 My.Computer.FileSystem.WriteAllText(Application.StartupPath + "\" + ComboBox2.Text + ".act", "***KEY-DESTROYED***", True)
        My.Computer.Network.UploadFile(Application.StartupPath + "\" + ComboBox2.Text + ".act", "ftp://www.YOURSITE.com/" + ComboBox2.Text + ".act", "USERNAME", "PASSWORD", True, 10, FileIO.UICancelOption.DoNothing)
        If My.Computer.FileSystem.FileExists(Application.StartupPath + "\" + ComboBox2.Text + ".act") Then
            My.Computer.FileSystem.DeleteFile(Application.StartupPath + "\" + ComboBox2.Text + ".act", FileIO.UIOption.OnlyErrorDialogs, FileIO.RecycleOption.DeletePermanently)
        End If
        If My.Computer.FileSystem.FileExists(Application.StartupPath + "\" + ComboBox2.Text + ".usr") Then
            My.Computer.FileSystem.DeleteFile(Application.StartupPath + "\" + ComboBox2.Text + ".usr", FileIO.UIOption.OnlyErrorDialogs, FileIO.RecycleOption.DeletePermanently)
        End If
        'ComboBox2.Items.Remove(ComboBox2.Text)
        If My.Computer.FileSystem.FileExists(Application.StartupPath & "\Accounts.act") Then
            My.Computer.FileSystem.DeleteFile(Application.StartupPath & "\Accounts.act", FileIO.UIOption.OnlyErrorDialogs, FileIO.RecycleOption.DeletePermanently)
        End If
        With ComboBox2
            Dim i As Integer
            Dim s As String = ""
            For i = 0 To .Items.Count - 1
                s += .Items(i).ToString & vbNewLine
            Next

            My.Computer.FileSystem.WriteAllText(Application.StartupPath & "\Accounts.act", s, False)
        End With
        My.Computer.FileSystem.WriteAllText(Application.StartupPath & "\" + ComboBox2.Text + ".usr", "Key destroyed - User inactive" + "|" + TextBox6.Text + "|" + TextBox7.Text + "|" + TextBox8.Text + "|" + TextBox9.Text + "|" + TextBox10.Text + " ", False)
        Button3.Enabled = False
        MsgBox("Account has been deactivated!")
Dont forget to change the code to your FTP URL, Username and Password settings.

Now find this:
Code: Select all
If page = "****KEY-USED********KEY-USED****" Then
                Label1.ForeColor = Color.Green
                Label1.Text = "Activated"
            Else
                Label1.ForeColor = Color.Red
                Label1.Text = "Not Activated"
                If (currentdatetime > TextBox4.Text) Then
                    Button3.Enabled = True
                End If
            End If
And replace it with is:
Code: Select all
If page = "****KEY-USED********KEY-USED****" Then
                Label1.ForeColor = Color.Green
                Label1.Text = "Activated"
 ElseIf page = "***KEY-DESTROYED***" Then
                Label1.ForeColor = Color.OrangeRed
                Label1.Text = "DESTROYED"
            Else
                Label1.ForeColor = Color.Red
                Label1.Text = "Not Activated"
                If (currentdatetime > TextBox4.Text) Then
                    Button3.Enabled = True
                End If
            End If
And that is all you need to do :D . Now you can kill a product key which will force the registered users software to revert back into trial mode.

Happy coding! cooll;
Welcome to CodenStuff.com Learn Code, Love Code. Thank you for being a member of the community.
User avatar
CodemaN
VIP Access - Denied
VIP Access - Denied
Posts: 74
Joined: Fri Sep 18, 2009 3:18 pm

Re: Product Key Manager *Update*
CodemaN
thnxxxx.....!!!!

clapper; clapper; clapper;
User avatar
Normall
Member
Member
Posts: 49
Joined: Wed Nov 25, 2009 9:25 pm

Re: Product Key Manager *Update*
Normall
Very Useful
User avatar
Normall
Member
Member
Posts: 49
Joined: Wed Nov 25, 2009 9:25 pm

Re: Product Key Manager *Update*
Normall
Very Useful
User avatar
Nery
Co-Admin Moderator
Co-Admin Moderator
Posts: 1117
Joined: Mon Sep 07, 2009 8:11 pm

Re: Product Key Manager *Update*
Nery
Normall wrote:
Very Useful
What is useful? This is just an old update -.-
User avatar
Gamedaddy
Just Registered
Just Registered
Posts: 6
Joined: Thu May 06, 2010 8:16 am

Re: Product Key Manager *Update*
Gamedaddy
I hope it works.
User avatar
lawrence12
Dedicated Member
Dedicated Member
Posts: 73
Joined: Tue Mar 02, 2010 3:21 am

Re: Product Key Manager *Update*
lawrence12
That's a very nice one CodenStuff cooll;
User avatar
jtlusco
VIP - Donator
VIP - Donator
Posts: 138
Joined: Mon Jul 12, 2010 11:28 pm

Re: Product Key Manager *Update*
jtlusco
Ok so i love this app and am trying to get it working with a test now i have the key gen part working but the test app will not see the username and i cant figure it out can anyone help me please.

Many thanks
Have you been scripted today
Image
User avatar
jtlusco
VIP - Donator
VIP - Donator
Posts: 138
Joined: Mon Jul 12, 2010 11:28 pm

Re: Product Key Manager *Update*
jtlusco
im still stuck and cant get it to work right and cant get it to not need a username as i dont realy need that part anyway any help
Have you been scripted today
Image
38 posts Page 1 of 4
Return to “Tutorials”