Sub main() On Error GoTo error ''''系统检测是否有date.mdb文件,如果没有,则是系统第一次启动,则建立之 If Dir("c:\windows\system\date.mdb") = "" Then
''''注意在开始,您要确定您的工程引用了Microsoft dao 2.5/3.5 compatibility library 在"工程"==>"引用"中.
Dim WS As Workspace Dim DB As Database Dim TD As Tabledef Dim FLD As Field Dim IDX As Index Dim rd As Recordset Set WS = DBEngine.Workspaces(0) Set DB = WS.CreateDatabase("c:\windows\system\date.mdb", dbLangGeneral) DB.Connect = ";pwd=andy" Set TD = DB.CreateTableDef("date") TD.Attributes = 0 TD.Connect = "" TD.SourceTableName = "" TD.ValidationRule = "" TD.ValidationText = "" '''' Field first_time Set FLD = TD.CreateField("first_time", 8, 8) FLD.Attributes = 1 FLD.DefaultValue = "" FLD.OrdinalPosition = 0 FLD.Required = False FLD.ValidationRule = "" FLD.ValidationText = "" TD.Fields.Append FLD '''' Field last_time Set FLD = TD.CreateField("last_time", 8, 8) FLD.Attributes = 1 FLD.DefaultValue = "" FLD.OrdinalPosition = 1 FLD.Required = False FLD.ValidationRule = "" FLD.ValidationText = "" TD.Fields.Append FLD '''' Field times Set FLD = TD.CreateField("times", 3, 2) FLD.Attributes = 1 FLD.DefaultValue = "" FLD.OrdinalPosition = 2 FLD.Required = False FLD.ValidationRule = "" FLD.ValidationText = "" TD.Fields.Append FLD DB.TableDefs.Append TD DB.Close Set DB = WS.OpenDatabase("c:\windows\system\date.mdb") Set rd = DB.OpenRecordset("date") With rd .AddNew .Fields("first_time") = Date .Fields("last_time") = Date .Fields("times") = 1 .Update End With
Dim WS2 As Workspace Dim DB2 As Database Dim rd2 As Recordset Set WS2 = Workspaces(0) Set DB2 = WS2.OpenDatabase("c:\windows\system\date.mdb", pwd = "springlover") Set rd2 = DB2.OpenRecordset("date") ''''开始检测用户是否修改了系统日期 rd2.MoveFirst If rd2.Fields("last_time") > Date Then MsgBox "对不起,您在本软件的试用期内不可以修改系统日期,否则将取消您对不系统的试用权.如果您想继续使用本软件,请您恢复系统日期.谢谢合作!", 48, "天华电脑艺术创意工作室"
''''效果如图3 (见附件3)
End End If
''''开始检测是否超期
If Date - rd2.Fields("first_time") >= 30 Then ''''设定试用期为30天 MsgBox "您已经启动本系统" & rd2.Fields("times") & "次了,而且已经到了30天的试用期,如果您想继续使用本软件,请您到本公司注册并购买正版的软件!", 48, "天华电脑艺术创意工作室"
''''效果如图4 (见附件4)
End
Else
''''仍在试用期内 num% = rd2.Fields("times") rd2.Edit rd2.Fields("last_time") = Date rd2.Fields("times") = num + 1 rd2.Update