VB [VB.Net] Crea seriali Trial e Expired per i propri programmi che vuoi vendere!

Stato
Discussione chiusa ad ulteriori risposte.

Ghost°Fantman

Utente Silver
9 Settembre 2011
4
2
0
51
questo che sto postando e un source di VB.Net siccome non riesco a sistemarlo perche e troppo incasinato e non capisco che cosa devo mettere nella grafica.

mi chiedevo se ci fosse qualcuno intenzionato ad aiutarmi ???

nel sorce code ci sono delle limitazioni demo ma non riesco a capire cosa devo eliminare???? per toglierle booo!

Codice:
#Region "  O P T I O N S  "

Option Explicit On
Option Strict On

#End Region

'===================================================================================================
'=====            This code shows you how to implement Serial Key Maker in your application, 
'=====            using YOUR private key (MyTestPrivateKey!)!
'=====            
'=====            NOTE:  Before you deploy this code:
'=====                DELETE ALL instances of your UNENCRYPTED private key in THIS file.
'=====                Leave all instances of the encrypted key (k5YearC8F5KvpCNDyLqxJVX+7bpmU+Wcm578CdwuCF4=)
'=====            
'=====            
'=====            To get this code running.
'=====            
'=====            1.    Create a New Project
'=====            2.    Select "Visual Basic" - > Windows Forms Application
'=====            3.    DELETE the From1.vb file
'=====            4.    Add a New *Class* to the application
'=====            5.    Copy and paste this entire document into the new class (replacing the code  
'=====                    that is alreadyin the class file - "Public Class Class1...End Class")
'=====            6.    Now Add a reference to the PG_SerialKeyMaker_API DLL
'=====            
'=====            Application should now compile and run.
'===================================================================================================

'--------------------------------------------------------------------------------------
'---    This demo shows how to implement a DEMO version application with limited features, 
'---    or how to unlock the same applicaiton to the full version
'--- 
'---    In the example, we will let the "PI" functionality be allowed in demo mode,
'---    but not if the demo has expired.
'--- 
'---    The "diameter" functionality will only be allowed if this is a registered full version
'--- 
'---    Note, the application uses hard coded registration keys that were generated with the 
'---    private key "MyTestPrivateKey!"
'--- 
'---    This is set in the code in the declarations section:
'--- 
'---       Private Const mc_strMyPrivateKey As String = "k5YearC8F5KvpCNDyLqxJVX+7bpmU+Wcm578CdwuCF4=" '--- encrypted private key ("MyTestPrivateKey!")
'--- 
'---    The "ReadSerialNumber" method returns a hard coded serial number. 
'---    There is a unlimited (never expires) key and a DEMO key.  The 
'---    DEMO key expires on 8/9/2010.  If you are running this demo app after
'---    that date, you will see the following error message:
'--- 
'---        "Your trial period has expired.  Please purchase XXX at www.xyz.com"
'--- 
'---    You should create a new demo key to use, using the Private Key used above.
'--- 
'--------------------------------------------------------------------------------------

#Region " I M P O R T S "

'--- MAKE SURE YOU HAVE REFERENCED THE SERIAL KEY MAKER API
'--- BROWSE TO THE FILE "PG_SerialKeyMaker_API.dll"
Imports PG.SerialKeyMaker.Utility.API


#End Region

Public Class Form1

#Region "  P R I V A T E   D E C L A R A T I O N S   "

    '--- reference and import PG.SerialKeyMaker.Utility.Logging
    '--- the API requires a valid log object to work with
    Private m_objLogObject As classLogging
    Private Const mc_strLogFileAndPath As String = "c:\log\test.log"


    '---- NOTE:     In practice you would NOT store your private key in the code 
    '----           as PLAIN TEXT.  You should ENCRYPT it (and even double encrypt it - do it twice)
    '----           and then store it in the code as a constant or in an encrypted file
    '----           for deploy with your application.  You would then read it, and DECRYPT
    '----           it just before using it in your application.
    '----   
    '----           <delete this comment before you deploy if you are copying this code>
    '----               This is the encrypted version of "MyTestPrivateKey!".  It is
    '----               encrypted with the SaltShaker.Salt class in this file, and the encryption routine below.
    '----               To encrypt, simply start your app in debug mode, set a break point in Form_Load
    '----               and run this in the Immediate Window:
    '----               ?EncryptMD5("MyTestPrivateKey!", SaltShaker.Salt)
    '----           </delete this comment before you deploy if you are copying this code>
    '----
    Private Const mc_strMyPrivateKey As String = "k5YearC8F5KvpCNDyLqxJVX+7bpmU+Wcm578CdwuCF4=" '--- encrypted private key

    '---- m_objLicense is initialized in the form load event,
    '---- and used throughout the application to validate that the application
    '---- has been registered, or is in demo mode.
    Private m_objLicense As PG.SerialKeyMaker.Utility.API.classLicense


#End Region

#Region "  P R O P E R T I E S  "

    Public ReadOnly Property LogObject() As classLogging

        Get
            '--- set the properties of the new log object
            If m_objLogObject Is Nothing Then

                m_objLogObject = New classLogging(mc_strLogFileAndPath)
                m_objLogObject.LoggingIsEnabled = True
                m_objLogObject.ConsoleIsOn = False
                m_objLogObject.TraceIsOn = False
                m_objLogObject.UseHourlyLoggingFilename = False

            End If

            Return m_objLogObject

        End Get

    End Property

#End Region

#Region "  P R I V A T E   M E T H O D S  "


    '---- In practice, when the user enters their serial number to use, or unlock,
    '---- your application, you will ENCRYPT and then store that serial number in 
    '---- a file or in thier registry.
    '----
    '---- When the serial number is needed to be checked by your application
    '---- you will read from the user's hard disk (or registry) to find where you 
    '---- stored the encrypted version of this application's serial number, then DECRYPT it.
    '---- and validate it
    '---- 
    '---- For simplicity of this demo, I am just going to hard-code an encrypted key.
    '---- 
    '---- Also, notice that I "read" the serial number in many different locations
    '---- Consider storing the serial number in a variable to reduce the number of reads
    '---- especially if it's an encrypted file store.


    Private Function ReadSerialNumber() As String

        '----   for the purpose of this demo I have created an unlimited key 
        '----   using the private key (mc_strMyPrivateKey) declared above.
        '----
        '---- This demo key was created with the folowing options: 
        '----     -   The license key is created with the Private Key you have in the Serial Key Maker UI.
        '----     -   Features 1 and 2 are enabled
        '----     -   Limited license key lasts for 14 days
        '----     -   An UNLimited license is only created if you own a valid copy of Serial Key Maker
        '----     -   Machine Code is not used.
        '----     -   Freeform Text is not used.
        '----
        '----           <delete this comment before you deploy if you are copying this code>
        '----                   This license key "TDNNK-DFUNH-MFBMO-VNSPW" was encrypted with the
        '----                   salt shaker class in this file. Decrypt it before using, 
        '----                   by calling the "DecryptMD5" function below.
        '----               To encrypt, simply start your app in debug mode, set a break point in Form_Load
        '----               and run this in the Immediate Window:
        '----                   ?EncryptMD5("TDNNK-DFUNH-MFBMO-VNSPW", SaltShaker.Salt)
        '----           <delete this comment before you deploy if you are copying this code>

        '----           NOTE:  If you own a registered copy of Serial Key Maker, generate an UNLIMITED key and replace the one below.
        '----           NOTE:  You can only create UNLIMITED keys with the fully paid version of Serial Key Maker

        Dim m_strSerialKey_Unlimited As String = "RmBdjfYmm31X9+ULBhNQyPpwg3ad+1EopeQ0C2KAaZE=" '-- encrypted unlimited key

        '----   and a DEMO key.  By the time you use this demo, this time limited demo may have expired.
        '----   use Serial Key Maker to generate another demo key using the "mc_strMyPrivateKey" 
        '----   declared above as the private key

        '----           <delete this comment before you deploy if you are copying this code>
        '----                   This license key "TRAUW-LQJNH-FSBMY-CNSLI" was encrypted with the
        '----                   saltshaker class in this file.  Decrypt it before using, 
        '----                   by calling the "DecryptMD5" function below.
        '----               To encrypt, simply start your app in debug mode, set a break point in Form_Load
        '----               and run this in the Immediate Window:
        '----                   ?EncryptMD5("TRAUW-LQJNH-FSBMY-CNSLI", SaltShaker.Salt)
        '----           <delete this comment before you deploy if you are copying this code>
        Dim m_strSerialKey_Limited As String = "qR1TBZVjpDe4lpsa75PLDAOO3775FEgtBLEoUxI+7x4="  '--- expires 8/9/2010


        '--- toggle these two around if you want to switch between demo and unlimted functionality
        Return m_strSerialKey_Unlimited
        ' Return m_strSerialKey_Limited '--- uncomment if you want to test the DEMO version code

    End Function


    Private Sub ShowNagScreen(Optional ByVal p_blnFunctionalityRestriction As Boolean = False)

        Dim strMessage As String = String.Empty
        'TODO:  Implement a real nag screen form telling the user they are in demo mode, or that their demo has expired
        '       I will just make an ugly msg box :)

        '--- if we are here, we are not fully registered, either in demo mode, or expired status
        If m_objLicense.ValidateKey(DecryptMD5(ReadSerialNumber, SaltShaker.Salt)).IsCurrentlyValid Then

            strMessage = "In DEMO mode. Thank you for using XYZ" & vbCrLf & vbCrLf
            strMessage += "Your key was created on " & m_objLicense.ValidateKey(DecryptMD5(ReadSerialNumber, SaltShaker.Salt)).DateCreated & vbCrLf
            strMessage += "and is valid until " & m_objLicense.ValidateKey(DecryptMD5(ReadSerialNumber, SaltShaker.Salt)).DateValidThrough

            If p_blnFunctionalityRestriction Then

                '--- if we are showing this as a functionality restricition then add to the text
                strMessage += vbCrLf & vbCrLf & "This functionality is not allowed in the DEMO version."

            End If

            MessageBox.Show(strMessage, "Demo Version Nag Screen", MessageBoxButtons.OK, MessageBoxIcon.Information)

        Else

            strMessage = "Your trial period has expired.  Please purchase XXX at www.xyz.com"

            MessageBox.Show(strMessage, "Demo Version", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)

        End If


    End Sub

    Private Sub ShowPI()

        Dim dblPI As Double = 0

        '---- NOTE:  We will check the status of the key again here in case they did a hack jump over the previous check

        '--- in this case we do not care if they key is demo or full, just that it is not expired because 
        '--- this functionality is allowed in demo mode.  If expired, then do not allow this functionality

        If m_objLicense.ValidateKey(DecryptMD5(ReadSerialNumber, SaltShaker.Salt)).IsCurrentlyValid Then

            dblPI = CalculatePI()
            MessageBox.Show("Pi is:" & vbCrLf & dblPI.ToString, "Congratulations!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)

        Else

            ShowNagScreen()
            '--- consider exiting the program
            '--- End

        End If


    End Sub

    Private Sub ShowCircumference(ByVal p_intDiamter As Integer)

        Dim dblCircumference As Double = 0
        Dim strResult As String = String.Empty

        '---- NOTE:  We will check the status of the key again here in case they did a hack jump over the previous check

        '--- In this case we DO care if they key is a DEMO or FULL.  
        '--- This functionaility is not available for DEMO users.  If expired, then do not allow this functionality either

        If m_objLicense.ValidateKey(DecryptMD5(ReadSerialNumber, SaltShaker.Salt)).IsCurrentlyValid AndAlso _
                    Not (m_objLicense.ValidateKey(DecryptMD5(ReadSerialNumber, SaltShaker.Salt)).Expires) Then

            dblCircumference = CalculateCircumference(p_intDiamter)
            MessageBox.Show("Circumference is:" & vbCrLf & dblCircumference.ToString, "Congratulations!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)

        Else

            ShowNagScreen()
            '--- consider exiting the program
            '--- End

        End If


    End Sub

    Private Sub ShowDiameter(ByVal p_intRadius As Integer)

        Dim dblDiameter As Double = 0
        Dim strResult As String = String.Empty

        '---- NOTE:  We will check the status of the key again here in case they did a hack jump over the previous check

        '--- ONLY allow this functionlity if the "Feature2" value is set to true in the license key.
        If ((Not m_objLicense.ValidateKey(DecryptMD5(ReadSerialNumber, SaltShaker.Salt)).Expires) _
                    AndAlso m_objLicense.ValidateKey(DecryptMD5(ReadSerialNumber, SaltShaker.Salt)).IsCurrentlyValid _
                    AndAlso m_objLicense.ValidateKey(DecryptMD5(ReadSerialNumber, SaltShaker.Salt)).Feature2 = True) Then

            dblDiameter = p_intRadius * 2

            strResult = "Diameter is:" & vbCrLf & dblDiameter.ToString
            strResult += vbCrLf & "Feature 1 is " & m_objLicense.ValidateKey(DecryptMD5(ReadSerialNumber, SaltShaker.Salt)).Feature1.ToString
            strResult += vbCrLf & "Feature 2 is " & m_objLicense.ValidateKey(DecryptMD5(ReadSerialNumber, SaltShaker.Salt)).Feature2.ToString
            strResult += vbCrLf & "Feature 3 is " & m_objLicense.ValidateKey(DecryptMD5(ReadSerialNumber, SaltShaker.Salt)).Feature3.ToString

            MessageBox.Show(strResult, "Congratulations!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)

        Else

            ShowNagScreen()
            '--- consider exiting the program
            '--- End

        End If

    End Sub

#Region " E N C R Y P T I O N   R O U T I N E S  "

    '----------------------------------------------------------------------------------------------------------------------
    '----       This sample is adapted from code I found at:
    '----       http://www.obviex.com/samples/Encryption.aspx
    '----------------------------------------------------------------------------------------------------------------------

    '---- DECLARE SOME CONSTANTS
    Private m_strPassPhrase As String = "MyPriv@Password!$$"    '---- any text string is good here
    Private m_strHashAlgorithm As String = "MD5"                '--- we are doing MD5 encryption - can be "SHA1"
    Private m_strPasswordIterations As Integer = 2              '--- can be any number
    Private m_strInitVector As String = "@1B2c3D4e5F6g7H8"      '--- must be 16 bytes
    Private m_intKeySize As Integer = 256                       '--- can be 192 or 128

    Friend Function EncryptMD5(ByVal plainText As String, ByVal p_strSaltValue As String) As String

        Dim strReturn As String = String.Empty

        ' Convert strings into byte arrays.
        ' Let us assume that strings only contain ASCII codes.
        ' If strings include Unicode characters, use Unicode, UTF7, or UTF8 
        ' encoding.

        Try

            Dim initVectorBytes As Byte()
            initVectorBytes = System.Text.Encoding.ASCII.GetBytes(m_strInitVector)

            Dim saltValueBytes As Byte()
            saltValueBytes = System.Text.Encoding.ASCII.GetBytes(p_strSaltValue)

            ' Convert our plaintext into a byte array.
            ' Let us assume that plaintext contains UTF8-encoded characters.
            Dim plainTextBytes As Byte()
            plainTextBytes = System.Text.Encoding.UTF8.GetBytes(plainText)

            ' First, we must create a password, from which the key will be derived.
            ' This password will be generated from the specified passphrase and 
            ' salt value. The password will be created using the specified hash 
            ' algorithm. Password creation can be done in several iterations.
            Dim password As System.Security.Cryptography.PasswordDeriveBytes
            password = New System.Security.Cryptography.PasswordDeriveBytes(m_strPassPhrase, _
                                            saltValueBytes, _
                                            m_strHashAlgorithm, _
                                            m_strPasswordIterations)

            'Dim password As Rfc2898DeriveBytes

            'password = New Rfc2898DeriveBytes(m_strPassPhrase, _
            '                                saltValueBytes, _
            '                                m_strPasswordIterations)



            ' Use the password to generate pseudo-random bytes for the encryption
            ' key. Specify the size of the key in bytes (instead of bits).
            Dim keyBytes As Byte()
            Dim intKeySize As Integer = 0

            intKeySize = CType((m_intKeySize / 8), Integer)

            keyBytes = password.GetBytes(intKeySize)

            ' Create uninitialized Rijndael encryption object.
            Dim symmetricKey As System.Security.Cryptography.RijndaelManaged
            symmetricKey = New System.Security.Cryptography.RijndaelManaged

            ' It is reasonable to set encryption mode to Cipher Block Chaining
            ' (CBC). Use default options for other symmetric key parameters.
            symmetricKey.Mode = System.Security.Cryptography.CipherMode.CBC

            'symmetricKey.Padding = PaddingMode.Zeros


            ' Generate encryptor from the existing key bytes and initialization 
            ' vector. Key size will be defined based on the number of the key 
            ' bytes.
            Dim encryptor As System.Security.Cryptography.ICryptoTransform
            encryptor = symmetricKey.CreateEncryptor(keyBytes, initVectorBytes)

            ' Define memory stream which will be used to hold encrypted data.
            Dim memoryStream As System.IO.MemoryStream
            memoryStream = New System.IO.MemoryStream

            ' Define cryptographic stream (always use Write mode for encryption).
            Dim cryptoStream As System.Security.Cryptography.CryptoStream
            cryptoStream = New System.Security.Cryptography.CryptoStream(memoryStream, _
                                            encryptor, _
                                            System.Security.Cryptography.CryptoStreamMode.Write)
            ' Start encrypting.
            cryptoStream.Write(plainTextBytes, 0, plainTextBytes.Length)

            ' Finish encrypting.
            cryptoStream.FlushFinalBlock()

            ' Convert our encrypted data from a memory stream into a byte array.
            Dim cipherTextBytes As Byte()
            cipherTextBytes = memoryStream.ToArray()

            ' Close both streams.
            memoryStream.Close()
            cryptoStream.Close()

            ' Convert encrypted data into a base64-encoded string.
            Dim cipherText As String
            cipherText = Convert.ToBase64String(cipherTextBytes)

            ' Return encrypted string.
            strReturn = cipherText

        Catch ex As Exception
            strReturn = Nothing
        End Try

        Return strReturn

    End Function

    Friend Function DecryptMD5(ByVal cipherText As String, ByVal p_strSaltValue As String) As String

        Dim strReturn As String = String.Empty

        ' Convert strings defining encryption key characteristics into byte
        ' arrays. Let us assume that strings only contain ASCII codes.
        ' If strings include Unicode characters, use Unicode, UTF7, or UTF8
        ' encoding.

        Try

            Dim initVectorBytes As Byte()
            initVectorBytes = System.Text.Encoding.ASCII.GetBytes(m_strInitVector)

            Dim saltValueBytes As Byte()
            saltValueBytes = System.Text.Encoding.ASCII.GetBytes(p_strSaltValue)

            ' Convert our ciphertext into a byte array.
            Dim cipherTextBytes As Byte()
            cipherTextBytes = Convert.FromBase64String(cipherText)

            ' First, we must create a password, from which the key will be 
            ' derived. This password will be generated from the specified 
            ' passphrase and salt value. The password will be created using
            ' the specified hash algorithm. Password creation can be done in
            ' several iterations.
            Dim password As System.Security.Cryptography.PasswordDeriveBytes
            'Dim password As Rfc2898DeriveBytes

            'password = New Rfc2898DeriveBytes(m_strPassPhrase, _
            '                                saltValueBytes, _
            '                                m_strPasswordIterations)

            password = New System.Security.Cryptography.PasswordDeriveBytes(m_strPassPhrase, _
                                            saltValueBytes, _
                                            m_strHashAlgorithm, _
                                            m_strPasswordIterations)

            ' Use the password to generate pseudo-random bytes for the encryption
            ' key. Specify the size of the key in bytes (instead of bits).
            Dim keyBytes As Byte()
            Dim intKeySize As Integer

            intKeySize = CType((m_intKeySize / 8), Integer)

            keyBytes = password.GetBytes(intKeySize)

            ' Create uninitialized Rijndael encryption object.
            Dim symmetricKey As System.Security.Cryptography.RijndaelManaged
            symmetricKey = New System.Security.Cryptography.RijndaelManaged

            ' It is reasonable to set encryption mode to Cipher Block Chaining
            ' (CBC). Use default options for other symmetric key parameters.
            symmetricKey.Mode = System.Security.Cryptography.CipherMode.CBC

            'symmetricKey.Padding = PaddingMode.Zeros

            ' Generate decryptor from the existing key bytes and initialization 
            ' vector. Key size will be defined based on the number of the key 
            ' bytes.
            Dim decryptor As System.Security.Cryptography.ICryptoTransform
            decryptor = symmetricKey.CreateDecryptor(keyBytes, initVectorBytes)

            ' Define memory stream which will be used to hold encrypted data.
            Dim memoryStream As System.IO.MemoryStream
            memoryStream = New System.IO.MemoryStream(cipherTextBytes)

            ' Define memory stream which will be used to hold encrypted data.
            Dim cryptoStream As System.Security.Cryptography.CryptoStream
            cryptoStream = New System.Security.Cryptography.CryptoStream(memoryStream, _
                                            decryptor, _
                                            System.Security.Cryptography.CryptoStreamMode.Read)

            ' Since at this point we don't know what the size of decrypted data
            ' will be, allocate the buffer long enough to hold ciphertext;
            ' plaintext is never longer than ciphertext.
            Dim plainTextBytes As Byte()
            ReDim plainTextBytes(cipherTextBytes.Length)

            ' Start decrypting.
            Dim decryptedByteCount As Integer
            decryptedByteCount = cryptoStream.Read(plainTextBytes, _
                                                0, _
                                                plainTextBytes.Length)

            ' Close both streams.
            memoryStream.Close()
            cryptoStream.Close()

            ' Convert decrypted data into a string. 
            ' Let us assume that the original plaintext string was UTF8-encoded.
            Dim plainText As String
            plainText = System.Text.Encoding.UTF8.GetString(plainTextBytes, _
                                                0, _
                                                decryptedByteCount)

            ' Return decrypted string.
            strReturn = plainText

        Catch ex As Exception
            strReturn = Nothing
        End Try

        Return strReturn


    End Function

#End Region

#End Region

#Region "  F O R M   E V E N T S  "

    Private Sub frmMain_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        '--- initialize the license object for later use in the application
        '--- note how the license object is created by passing in the UN_ENCRYPTED Private Key
        m_objLicense = New classLicense(DecryptMD5(mc_strMyPrivateKey, SaltShaker.Salt), m_objLogObject)

    End Sub

    Private Sub btnPi_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPi.Click

        '---- see comments above at the declarations of mc_strMyPrivateKey, m_strSerialKey_Unlimited and m_strSerialKey_Limited

        '--- We will use the serial key validation to test if this is a registered copy:
        '---
        '---    If it is, we show no messages (the user is registered, and the app can continue)
        '---    If it is in time limited demo mode, show a nag screen.
        '---    If the demo has expired, then do not allow the functionality

        '--- It is good practice to put as many registration checks in your code as is practical
        '--- this makes it more difficult to hack your application using simple memory jumps
        If ((Not m_objLicense.ValidateKey(DecryptMD5(ReadSerialNumber, SaltShaker.Salt)).Expires) AndAlso m_objLicense.ValidateKey(DecryptMD5(ReadSerialNumber, SaltShaker.Salt)).IsCurrentlyValid) Then

            '---- does not expire, and is valid
            '---- we are fully registered, we can proceed
            ShowPI()

        Else
            '---- it either expires, or has already expired
            '---- show the nagscreen, we do not have a valid demo or registered version
            ShowNagScreen()

            If m_objLicense.ValidateKey(DecryptMD5(ReadSerialNumber, SaltShaker.Salt)).IsCurrentlyValid Then
                '--- in valid demo mode, can show PI
                ShowPI()

            End If


        End If


    End Sub

    Private Sub btnCircumference_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCircumference.Click


        '---- see comments above at the declarations of mc_strMyPrivateKey, m_strSerialKey_Unlimited and m_strSerialKey_Limited

        '--- We will use the serial key validation to test if this is a registered copy:
        '---
        '---    If it is, we show no messages (the user is registered, and the app can continue)
        '---    If it is in time limited demo mode, show a nag screen, and DO NOT allow the functionality.
        '---    If the demo has expired, then do not allow the functionality

        '--- It is good practice to put as many registration checks in your code as is practical
        '--- this makes it more difficult to hack your application using simple memory jumps
        If ((Not m_objLicense.ValidateKey(DecryptMD5(ReadSerialNumber, SaltShaker.Salt)).Expires) AndAlso m_objLicense.ValidateKey(DecryptMD5(ReadSerialNumber, SaltShaker.Salt)).IsCurrentlyValid) Then

            '---- does not expire, and is valid
            '---- we are fully registered, we can proceed
            ShowCircumference(100)

        Else
            '---- it either expires, or has already expired
            '---- show the nagscreen, we do not have a valid registered version
            ShowNagScreen(True)


        End If
    End Sub

    Private Sub btnDiameter_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDiameter.Click

        '--- Uses Feature locking

        '---- see comments above at the declarations of mc_strMyPrivateKey, m_strSerialKey_Unlimited and m_strSerialKey_Limited

        '--- We will use the serial key validation to test if this is a registered copy:
        '---
        '---    If it is, then we need to check if this feature is enabled.  This feature will on be available if 
        '---    the key supplied has feature "2" set, which the two keys in "ReadSerialNumber" have.

        '--- It is good practice to put as many registration checks in your code as is practical
        '--- this makes it more difficult to hack your application using simple memory jumps
        If ((Not m_objLicense.ValidateKey(DecryptMD5(ReadSerialNumber, SaltShaker.Salt)).Expires) _
                    AndAlso m_objLicense.ValidateKey(DecryptMD5(ReadSerialNumber, SaltShaker.Salt)).IsCurrentlyValid _
                    AndAlso m_objLicense.ValidateKey(DecryptMD5(ReadSerialNumber, SaltShaker.Salt)).Feature2 = True) Then

            '---- does not expire, and is valid
            '---- we are fully registered, we can proceed
            ShowDiameter(50)

        Else
            '---- it either expires, or has already expired
            '---- show the nagscreen, we do not have a valid registered version
            ShowNagScreen(True)


        End If

    End Sub

#End Region

#Region "  M A T H "

    Private Function CalculatePI() As Double
        Dim dblReturn As Double
        Dim intNum As Integer = 22
        Dim intDen As Integer = 7

        Try

            dblReturn = CType((intNum / intDen), Double)

        Catch ex As Exception

            '---- oops.  Just cheat
            dblReturn = 3.14

        End Try

        Return dblReturn

    End Function

    Private Function CalculateCircumference(ByVal p_intDiameter As Integer) As Double
        Dim dblReturn As Double
        Dim dblPI As Double

        Try

            '--- get PI
            dblPI = CalculatePI()

            '--- circumference is PI X diameter
            dblReturn = dblPI * p_intDiameter

        Catch ex As Exception

            '---- oops. 
            dblReturn = -1

        End Try

        Return dblReturn

    End Function

#End Region

End Class

'--- I have moved the designer generated code into this file to keep all the code in one place.
'--- It will still compile and run fine, but the designer view will show a blank form
'--- and try to add a new "InitializeComponent" method if you alter the form in design mode,
'--- which creates a "duplicate signature" error.
'--- If that happens, you can just undo that by deleting the added "InitializeComponent" method. 
#Region "  D E S I G N E R   G E N E R A T E D   C O D E"

<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class Form1
    Inherits System.Windows.Forms.Form

    'Form overrides dispose to clean up the component list.
    <System.Diagnostics.DebuggerNonUserCode()> _
    Protected Overrides Sub Dispose(ByVal disposing As Boolean)
        Try
            If disposing AndAlso components IsNot Nothing Then
                components.Dispose()
            End If
        Finally
            MyBase.Dispose(disposing)
        End Try
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    <System.Diagnostics.DebuggerStepThrough()> _
    Private Sub InitializeComponent()
        Me.btnPi = New System.Windows.Forms.Button
        Me.btnCircumference = New System.Windows.Forms.Button
        Me.btnDiameter = New System.Windows.Forms.Button
        Me.SuspendLayout()
        '
        'btnPi
        '
        Me.btnPi.Location = New System.Drawing.Point(12, 12)
        Me.btnPi.Name = "btnPi"
        Me.btnPi.Size = New System.Drawing.Size(168, 23)
        Me.btnPi.TabIndex = 0
        Me.btnPi.Text = "Calculate Pi"
        Me.btnPi.UseVisualStyleBackColor = True
        '
        'btnCircumference
        '
        Me.btnCircumference.Location = New System.Drawing.Point(12, 81)
        Me.btnCircumference.Name = "btnCircumference"
        Me.btnCircumference.Size = New System.Drawing.Size(168, 23)
        Me.btnCircumference.TabIndex = 1
        Me.btnCircumference.Text = "Calculate Circumference"
        Me.btnCircumference.UseVisualStyleBackColor = True
        '
        'btnDiameter
        '
        Me.btnDiameter.Location = New System.Drawing.Point(12, 46)
        Me.btnDiameter.Name = "btnDiameter"
        Me.btnDiameter.Size = New System.Drawing.Size(168, 23)
        Me.btnDiameter.TabIndex = 2
        Me.btnDiameter.Text = "Calculate Diameter"
        Me.btnDiameter.UseVisualStyleBackColor = True
        '
        'frmMain
        '
        Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
        Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
        Me.ClientSize = New System.Drawing.Size(250, 131)
        Me.Controls.Add(Me.btnDiameter)
        Me.Controls.Add(Me.btnCircumference)
        Me.Controls.Add(Me.btnPi)
        Me.Name = "frmMain"
        Me.Text = "Simple Application"
        Me.ResumeLayout(False)

    End Sub
    Friend WithEvents btnPi As System.Windows.Forms.Button
    Friend WithEvents btnCircumference As System.Windows.Forms.Button
    Friend WithEvents btnDiameter As System.Windows.Forms.Button

End Class

#End Region

#Region "  S A L T   C O D E   "


Public Class SaltShaker

    Public Shared ReadOnly Property Salt() As String
        Get

            ' This can be any string.  You can store it in your users registry or in a file.
            Return "A45%pQwcVbTpLaaWQrt"

        End Get
    End Property

End Class

#End Region

grazie per chi mi aiuta e mi spiega passo per passo dove inserire questo codice!
 
non è incasinato visto che è pieno di commenti, sei tu che non sei ancora al livello di gestire una funzione del genere. E, scommetto che anche il programma che vuoi realizzare trial non ne sarà altezza visto che non riesci a gestire nemmeno questo.
 
il fatto che io lo postato il source non vuol dire che io non ho capito quello che c'è scritto!
lunica cosa che chiedevo era di "eliminare le parti trial" dal source.

saresti cosi gentile da aiutarmi ???? Luka360
 
Stato
Discussione chiusa ad ulteriori risposte.