用VB制作注册软件的方法

Private Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
Private Declare Function GetVolumeInformation Lib "kernel32" Alias "GetVolumeInformationA" (ByVal lpRootPathName As String, ByVal lpVolumeNameBuffer As String, ByVal nVolumeNameSize As Long, lpVolumeSerialNumber As Long, lpMaximumComponentLength As Long, lpFileSystemFlags As Long, ByVal lpFileSystemNameBuffer As String, ByVal nFileSystemNameSize As Long) As Long
''此模块的作用是检测用程序所在机器C盘序列号并存入一个加密后的文本文件yibao.ini中,
''在每次运行时检测C盘序列号并与加密文本文件中的相应值进行比较如果不符提示用户进行注册

Public Reg_C As String
Public Reg_Key As Long
Public Jia_Mi_File As String
Public Jia_Mi_Char As String
Public Fso As New FileSystemObject
Public Ctf As TextStream



Public Function Jia_Mi_Txt()
Reg_C = Abs(GetSerialNumber("c:"))
If Dir(App.Path & "\yibao.ini") = "" Then
''建立一个文本文件
Open App.Path & "\yibao.ini" For Output As #1
Print #1, "00000000"
Close #1
End If

Jia_Mi_File = App.Path & "\yibao.ini"
Set Fso = CreateObject("Scripting.FileSystemObject")

Set Ctf = Fso.OpenTextFile(Jia_Mi_File, 1) ''建立 TextStream 对象 CTF

Jia_Mi_Char = ""
Do While Ctf.AtEndOfStream <> True

Jia_Mi_Char = Jia_Mi_Char & Chr(58 Xor Asc(Ctf.Read(1)))
Loop

Ctf.Close
Set Ctf = Nothing

If Jia_Mi_Char <> Int(Reg_C * 18 / 22 * 16 / 19) Then
''显示注册对话框
Dialog.Show 1
End If

End Function


''Text2.Text = Len(Reg_C)


Function GetSerialNumber(sroot As String) As Long
Dim lserialnum As Long
Dim r As Long
Dim strlabel As String, strtype As String
strlabel = String$(255, Chr$(0))
strtype = String$(255, Chr$(0))
r = GetVolumeInformation(sroot, strlabel, Len(strlabel), lserialnum, 0, 0, strtype, Len(strtype))
GetSerialNumber = lserialnum
''在 strLabel 中为磁盘卷标
''在 strType 中为文件系统类型
End Function

''此部分为程序加密处理模块,负责将C盘的卷标读并转换成数字
''对这串数字与58进行异或处理,得到一个加密的字符串写入yibao.ini中
''在每次运行时与文档中的加密后字符串进行反解密比较,不成功提示用户进行注册
最后修改:2019 年 03 月 04 日 02 : 42 PM
如果觉得我的文章对你有用,请随意赞赏

发表评论