Product Key Management System

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.
72 posts Page 2 of 8
User avatar
cricketgd
Just Registered
Just Registered
Posts: 3
Joined: Sun Nov 01, 2009 7:58 pm

Re: Product Key Management System
cricketgd
Thanks for reply, I have tried gmx for email and gmail - both didn't work. A Plus awardspace for ftp but it highlights: (Dosen't highlight try, just tell you what it's after)
Try
theClient.Send(theMailMessage)

And says: Smpt exception was unhandled

I checked over and I'm sure everything is right: Here is my code/Yours...:
Code: Select all
Imports System.Net
Imports System.IO
Imports System.Net.mail
Imports System.Data
Public Class Form1
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim rand As New Random()
        Dim length As Integer
        Dim randomString As String
        length = rand.Next(15, 15)
        randomString = ""
        For i As Integer = 1 To length
            randomString &= Chr(65 + rand.Next(20))
        Next
        Dim x As Integer
        Dim randnum As New Random
        x = rand.Next(10000000, 500000000)
        TextBox3.Text = randomString
        TextBox3.Text = TextBox3.Text + x.ToString
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        If TextBox1.Text = "" Then
            MsgBox("Email address is blank")
        ElseIf TextBox2.Text = "" Then
            MsgBox("Username is blank")
        End If
        'Sends the email and attachment
        Dim trialtime As Date = Now.AddDays(1)
        Dim from As New MailAddress("xxxxxxx@gmx.com")
        Dim [to] As New MailAddress(TextBox1.Text)
        Dim theMailMessage As New MailMessage(from, [to])
        theMailMessage.Body = "Thank you for purchasing " + ComboBox1.Text + vbNewLine + vbNewLine + "Your activation details are below." + vbNewLine + vbNewLine + "Username: " + TextBox2.Text + vbNewLine + vbNewLine + "Product Key: " + TextBox3.Text
        theMailMessage.Subject = ComboBox1.Text + " Product Key"
        Dim theClient As New SmtpClient("smpt.gmx.com")
        theClient.UseDefaultCredentials = False
        Dim theCredential As New System.Net.NetworkCredential("xxxxxxxx@gmx.com", "xxxxxxxxx")
        theClient.Credentials = theCredential
        theClient.EnableSsl = True
        Try
            theClient.Send(theMailMessage)
        Catch wex As Net.WebException
            MessageBox.Show("Could not send email...check your settings.")
        End Try
        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.dangerdeleter.awardspace.info/" + TextBox2.Text + ".act", "xxxxxxxxx", "xxxxxxxxxx", 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
        'ComboBox1.Items.Add(TextBox1.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
        MsgBox("Activation Key Successfully Uploaded")
    End Sub

    Private Sub TextBox3_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox3.TextChanged
        If TextBox3.Text = "" Then
            Button2.Enabled = False
        Else
            Button2.Enabled = True
        End If
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ' Retrieve file list from PlayList.txt file to ListBox1
        If My.Computer.FileSystem.FileExists(Application.StartupPath & "\Accounts.act") Then
            Using sr As New IO.StreamReader(Application.StartupPath & "\Accounts.act")
                Dim item As String = sr.ReadLine
                While item <> Nothing
                    ComboBox2.Items.Add(item)
                    item = sr.ReadLine
                End While
            End Using
        End If
    End Sub

    Private Sub ComboBox2_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox2.SelectedIndexChanged
        If My.Computer.FileSystem.FileExists(Application.StartupPath & "\" + ComboBox2.Text + ".usr") Then
            Using sr As New IO.StreamReader(Application.StartupPath & "\" + ComboBox2.Text + ".usr")
                TextBox4.Text = sr.ReadLine
            End Using
        End If
        Dim currentdatetime As Date = Now.AddDays(1)
        Try

            Dim url As String = "http://www.dangerdeleter.awardspace.info/" + 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"
            Else
                Label7.ForeColor = Color.Red
                Label7.Text = "Not Activated"
                If (currentdatetime > TextBox4.Text) Then
                    Button3.Enabled = True
                End If
            End If

        Catch ex As Exception

        End Try
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        My.Computer.FileSystem.WriteAllText(Application.StartupPath + "\" + ComboBox2.Text + ".act", "****KEY-USED****", True)
        My.Computer.Network.UploadFile(Application.StartupPath + "\" + ComboBox2.Text + ".act", "ftp://www.dangerdeleter.awardspace.info/" + ComboBox2.Text + ".act", "xxxxxxxxxxx", "xxxxxxxxxx", 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
        Button3.Enabled = False
        MsgBox("Account has been deactivated!")
    End Sub
End Class
=-=- I don't think it ftp, it specificly highlights: theClient.Send(theMailMessage and I tried gmail and gmx. THANKS FOR QUICK RESPONSE< SORRY FOR MY LATE ONE! THANKS IN ADVANCE<><>CRICKETGD
User avatar
CodenStuff
Site Admin
Site Admin
Posts: 4392
Joined: Tue Aug 04, 2009 1:47 am

Hello,

Change this line:
Code: Select all
Dim theClient As New SmtpClient("smpt.gmx.com")
To this:
Code: Select all
Dim theClient As New SmtpClient("mail.gmx.com")
That should do it ;)
Welcome to CodenStuff.com Learn Code, Love Code. Thank you for being a member of the community.
User avatar
TheET
VIP-Member
VIP-Member
Posts: 105
Joined: Sun Nov 01, 2009 2:41 am

Re: Product Key Management System
TheET
Code: Select all
Dim tcode = Convert.ToString(My.Settings.activated)
        If (tcode = "1") Then
            Button1.Visible = False
        Else
            isittrial()
        End If
The "isittrial" show up a error , "Isittrail" not declared

How to fix this?
User avatar
CodenStuff
Site Admin
Site Admin
Posts: 4392
Joined: Tue Aug 04, 2009 1:47 am

Hello,

Have you included the "isittrial" sub code from the tutorial?
Code: Select all
Private Sub isittrial()
        Dim trialtime As Date = Now
        Dim currentdatetime As Date = Now
        trialtime = trialtime.AddDays(30) 'SET THIS TO HOWEVER MANY DAYS YOU WANT THE TRIAL TO RUN FOR
        Dim ttime = Convert.ToString(My.Settings.apptrial)
        If (ttime = "1") Then
            My.Settings.trialcode = trialtime
            My.Settings.apptrial = "0"
            My.Settings.Save()
        End If
        If (currentdatetime > trialtime) Then
            Dim theSecondForm As New Activate()
            theSecondForm.ShowDialog()
            Me.Close()
        End If
    End Sub
Welcome to CodenStuff.com Learn Code, Love Code. Thank you for being a member of the community.
User avatar
TheET
VIP-Member
VIP-Member
Posts: 105
Joined: Sun Nov 01, 2009 2:41 am

Re: Product Key Management System
TheET
Ok , thanks i got it working :) The best tutorial ever ! :D , keep on the good work CodenStuff
User avatar
TheET
VIP-Member
VIP-Member
Posts: 105
Joined: Sun Nov 01, 2009 2:41 am

Re: Product Key Management System
TheET
There's another problem occur , i activated one of my apps , then use the product key manager to kill the key , wehn i restart my app that key have been destroyed , it is still activated

What should i do ?
User avatar
TheET
VIP-Member
VIP-Member
Posts: 105
Joined: Sun Nov 01, 2009 2:41 am

Re: Product Key Management System
TheET
and also , what happen if i activated this app , then i copy the activated app , will the copied app activated ?
User avatar
challengy
VIP - Donator
VIP - Donator
Posts: 15
Joined: Fri Dec 25, 2009 3:53 am

Re: Product Key Management System
challengy
question1: do i have to change the ftp://www.YOURSITE.com/ so its like ftp://www.name.0catch.com/ or should it be http://www.name.0catch.com/ ?

also when i try to use the product key, it says invalid key. its the exact same usrname and key that i generated and when it was being uploaded no error messages poped up so i don't know whats wrong.
User avatar
Manitara
Just Registered
Just Registered
Posts: 5
Joined: Thu Oct 29, 2009 4:06 pm

Re: Product Key Management System
Manitara
Can you explain how i store the keys? :)
User avatar
judasis
Just Registered
Just Registered
Posts: 3
Joined: Sat Feb 13, 2010 11:50 pm

Re: Product Key Management System
judasis
You said ;
"Now we need to enter 3 new settings in here so ill tell you the name of the setting and its value which you need to enter

apptrial - value = 1
trialcode - value = leave this blank
activated - value = 0
"
at settings, what is the value data type? string ,boolean, or ? and scope will be user or application?
Or we are going to enter this settings to Resources section? i don't figure out.
Also, when i use ClickOnce, whenever app updates it will require activation. am i wrong?
And thanks this code. it is good designed
Judasis
PS. I use vb 2008
Last edited by judasis on Sun Feb 14, 2010 9:43 am, edited 1 time in total.
72 posts Page 2 of 8
Return to “Tutorials”