软件的加密——注册码实现原理
摘 要:
摘 要:很多共享软件有一定的试用期,试用期过后,需要注册才能够继续使用。注册时需要把使用软件时出现的一个序列号给人家发过去,而后产权所有人给你注册号码。并且一机一个号码,最大限度防止盗用别人的成果。下面介绍的就是在VB中获取计算机的硬件信息,从而通过一定的算法给出注册码,实现软件加密。
关键词:
关键词: 软件加密 注册码 防盗
——声明中建立如下代码:
String, ByVal nVolumeNameSize As Integer, lpVolumeSerialNumber As Long,lpMaximumComponentLength As Long, lpFileSystemFlags As Long, ByVal lpFileSystemNameBuffer As String, ByVal nFileSystemNameSize As Long) As Long
新建一个函数:
Function GetSerialNumber(strDrive As String) As Long
Dim SerialNum As Long
Dim Res As Long
Dim Temp1 As String
Dim Temp2 As String
Temp1 = String$(255, Chr$(0))
Temp2 = String$(255, Chr$(0))
Res = GetVolumeInformation(strDrive, Temp1, Len(Temp1), SerialNum, 0, 0, Temp2, Len(Temp2))
GetSerialNumber = SerialNum
End Function
单击“注册”按钮事件代码如下:
Private Sub Command1_Click()
If Text2 <> CStr(GetSerialNumber("C:")-123*9) Then //注册码算法
Else
Unload Me
//执行正常运行的代码
End If
End Sub
窗体激活代码如下:
Private Sub Form_Activate()
Text1.Text = GetSerialNumber("C:")
End Sub
整个程序运行后,出现两个文本框和一个“注册”按钮,一个文本框显示计算机硬盘序列号,第二个文本框需输入正确注册号,,点“注册”程序正常运行,否则程序要求输入正确序列号。
序列号。
Private Type OSVERSIONINFO
dwOSVersionInfoSize As Long
dwMajorVersion As Long
dwMinorVersion As Long
dwBuildNumber As Long
dwPlatformId As Long
szCSDVersion As String * 128 ' Maintenance string for PSS usage
End Type
Private Declare Function GetVersionEx Lib "kernel32" Alias "GetVersionExA" (lpVersionInformation As OSVERSIONINFO) As Long
Private Declare Function GetComputerName Lib "kernel32" Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Private Const VER_PLATFORM_WIN32_NT = 2
Private Const VER_PLATFORM_WIN32_WINDOWS = 1
Private Const VER_PLATFORM_WIN32s = 0
窗体激活代码如下:
Private Sub Form_Activate()
Dim len5 As Long, aa As Long
Dim cmprName As String
Dim osver As OSVERSIONINFO
cmprName = String(255, 0)
len5 = 256
aa = GetComputerName(cmprName, len5)
cmprName = Left(cmprName, InStr(1, cmprName, Chr(0)) - 1)
Set CPUs = GetObject("winmgmts:{impersonationLevel=impersonate}!\" & Computer & "rootcimv2").ExecQuery("select * from Win32_Processor")
For Each mycpu In CPUs
Text1.Text = mycpu.ProcessorId
Next
End Sub
下运行通过。
本文编号:14738
本文链接:https://www.wllwen.com/kejilunwen/ruanjiangongchenglunwen/14738.html