Serial number validation framework for the VBA implementation tool

Source: Internet
Author: User

For the password to decipher the author does not understand, before the activation of a variety of serial numbers also some speculation, their own according to the idea of a serial number verification of the small framework, the tool can also be used to protect the next ...

The main idea is: After the user opens the gadget, the system detects whether it is activated, if not activated, the system gives a random digital code (after each re-open will change), the user according to random code to the provider to request the corresponding activation code for activation

about whether the activation of the judgment: I do this, the normal activation will be in the registration table to write the corresponding value, if detected this value will not remind users to activate

1, random code generation, according to the random number rnd to generate a string of numbers satisfying the condition, directly on the code

Sub Setranid ()
Randomize
Dim Ranid as Long

Setrndid:
Ranid = Rnd * 100000000 + _
Rnd * 10000000 + _
Rnd * 1000000 + _
Rnd * 100000 + _
Rnd * 10000 + _
RND * 1000 + _
RND * 100 + _
RND * 10
If Ranid < 10000000 Or Ranid > 99999999 then GoTo setrndid
FrmCheckId.TextBox1.Value = Ranid

End Sub

Effects such as:

2, corresponding to the verification of the activation sequence number

In fact, what I do here is based on random code, through a set of rules to generate serial numbers, directly on the code, you can see the validation rules actually I have done the encapsulation, in this class: Mymethod.kusy

' Serial number settings
Sub Checktheid ()
On Error GoTo Err_checkid
Dim RId as Long
Dim SId as String
Dim MYFNC

RId = CLng (FrmCheckId.TextBox1.Value)
SId = FrmCheckId.TextBox2.Value
Set MYFNC = CreateObject ("Mymethod.kusy")

If Len (sId) >= 8 Then
If Myfnc.checkid (sId, rId) Then
MsgBox "Activated! ", vbinformation
IDFLG = True
Call Myfnc.regchk (IDFLG, REGFLG)
Unload Frmcheckid
End If
End If

Set MYFNC = Nothing
Exit Sub
Err_checkid:
MsgBox Err.Description, vbcritical

End Sub

3, the method of encapsulation class Kusy also posted out

(1) Check whether the registry has a key value, if not, write the Set key value, if any, return true, indicating that the tool is activated, no longer serial number activation processing

' Registry check and settings
Function Regchk (ByVal idflg As Boolean, ByRef Regflg as Boolean) as Boolean
On Error GoTo Err_regchk
Dim S as String

Regchk = False
Set WSH = CreateObject ("WSCRIPT. SHELL ")
s = WSH. RegRead (REGPK & pjname & "\" & RegX & "\" & KeyName)

Err_regchk:
If s = Keyval Then
REGFLG = True
Regchk = True
Else
REGFLG = False
Regchk = False
End If

If REGFLG = False and IDFLG = True Then
WSH. RegWrite REGPK & pjname & "\" & RegX & "\" & KeyName, Keyval
Regchk = True
End If

End Function

(2) Serial number generation rules, as follows, you can see the author arbitrarily set a set of rules, this is required to fill in the activation code

' Serial number obtained
Function Getmyid (ByVal rId as Long) as String
Dim ID (1 to 8) as Long
Dim FLG as String
Dim result as String

For i = 1 to 8
ID (i) = Mid (CStr (rId), I, 1)
Select case I
Case 1
ID (i) = ID (i) * Mod 9
Case 2
ID (i) = ID (i) * Mod 7
Case 3
ID (i) = ID (i) * ID (i)
If ID (i) > ten then ID (i) = (ID (i)-) Mod 9
Case 4
If ID (i) > ID (i-1) then ID (i) = ID (i)-ID (i-1)
Case 5
ID (i) = ID (i) * 8 Mod 9
Case 6
ID (i) = ID (i) * Mod 9
Case 7
If ID (i) > 5 Then
ID (i) = ID (i)/2
Else
ID (i) = ID (i) + 1
End If
Case 8
ID (i) = Left (CStr (ID (i) * 9), 1)
End Select
Next

If ID (3) + ID (5) > 3 Then FLG = "K"
If ID (3) + ID (5) > 8 Then FLG = "U"
If ID (3) + ID (5) > Then FLG = "s"
If ID (3) + ID (5) > Then flg = "Y"

For each S-in ID
Result = result & S
Next

' result = Replace (Join (ID, ""), "", "")
Getmyid = result & FLG

End Function

(3) Verify the user input function, directly return the Boolean value, why write this instead of directly in the VBA code to determine whether the user input sequence number equals the rule generated? Because if you do not use the following function, the user can get the sequence number generated by debug directly in the VBE.

Function Checkid (ByVal sId as String, ByVal rId as Long) as Boolean
If sId = Getmyid (rId) Then
Checkid = True
Else
Checkid = False
End If

End Function

4, for the serial number generation rule code, can be independent, used to generate serial number value, this value to the user to activate

Such as:

(1) Administrator

(2) User

5, other tools can use this serial number verification framework, the use of the following methods

(1) Load DLL file on open, remove when close

Private Sub Workbook_Open ()
On Error GoTo Err_workopen
Application.Visible = False

' DLL loading
If Dir (Thisworkbook.path & "\mymethod.dll") <> "then
Shell "regsvr32/s" & Chr & Thisworkbook.path & "\mymethod.dll" & Chr (34)
Else
MsgBox "DLL file does not exist, please confirm! ", vbcritical
Exit Sub
End If

Frmcheckid.show
Application.Visible = True
Exit Sub
Err_workopen:
MsgBox Err.Description, vbcritical
End Sub

Private Sub workbook_beforeclose (Cancel as Boolean)
Shell "regsvr32/s u" & chr & Thisworkbook.path & "\mymethod.dll" & Chr (34)
End Sub

(2) Add UserForm to the tool

When initializing, call Kusy.regchk with the following code:

Private Sub userform_initialize ()
On Error GoTo Err_init
Dim IDFLG as Boolean
Dim MYFNC

HIDEFLG = False
Set MYFNC = CreateObject ("Mymethod.kusy")

' Check the Registry
If Myfnc.regchk (IDFLG, REGFLG) = True Then
HIDEFLG = True
GoTo endfrm
End If

With Frmcheckid
. Caption = "Serial Number verification--v1.1"
. BackColor = Colorconstants.vbwhite
. BorderStyle = Fmborderstylenone
. Width = 200
. Height = 120
End with

textbox1.enabled = False

Call Setranid
Set MYFNC = Nothing
ENDFRM:
Exit Sub
Err_init:
MsgBox Err.Description, vbcritical
End Sub

Serial number validation framework for the VBA implementation tool

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.