2个回答
展开全部
用个简单并且就好理解的方法。
做时间记录。输出一个隐秘路径如:%SystemRoot%\TimeRec.dat这个文件用来储存使用的时间,每次启动程序就读取里面的时间长度。如果大于三十天就关闭自身程序。
Private Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long
Private Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As Long
Private Sub LimTime()
Dim LastExitTime As String * 255
Dim FirstOpTime As String * 255
Dim RunDays As String * 255
Dim Ret As Long
If Dir("C:\Windows\RunExe.ini") = "" Then
FirstOpTime = Now
LastExitTime = Now
Ret = WritePrivateProfileString("ProgramInfo", "Author", "Cokie", "C:\Windows\RunExe.ini")
Ret = WritePrivateProfileString("ProgramInfo", "FirstOpTime", FirstOpTime, "C:\Windows\RunExe.ini")
Ret = WritePrivateProfileString("RunRecords", "RunDays", "0", "C:\Windows\RunExe.ini")
Ret = WritePrivateProfileString("RunRecords", "LastExitTime", LastExitTime, "C:\Windows\RunExe.ini")
Else
Ret = GetPrivateProfileString("RunRecords", "LastExitTime", "UnFound", LastExitTime, 255, "C:\Windows\RunExe.ini")
If Now <= CDate(LastExitTime) Then
MsgBox "你改变了系统时间,卑鄙!": Unload Me
Else
Ret = GetPrivateProfileString("RunRecords", "RunDays", "UnFound", RunDays, 255, "C:\Windows\RunExe.ini")
If CLng(RunDays) >= 30 Then
MsgBox "您的试用期已经到了!": Unload Me
Else
If Day(CDate(LastExitTime)) <> Day(Now) Then
RunDays = CStr(DateDiff("d", CDate(LastExitTime), Date) + CLng(RunDays))
Ret = WritePrivateProfileString("RunRecords", "Rundays", RunDays, "C:\Windows\RunExe.ini")
End If
End If
End If
End Sub
Private Sub Form_Load()
Call LimTime
End Sub
Private Sub Form_Unload(Cancel As Integer)
Dim LastExitTime As String * 255
LastExitTime = Now
Ret = WritePrivateProfileString("RunRecords", "LastExitTime", LastExitTime, "C:\Windows\RunExe.ini")
End Sub
做时间记录。输出一个隐秘路径如:%SystemRoot%\TimeRec.dat这个文件用来储存使用的时间,每次启动程序就读取里面的时间长度。如果大于三十天就关闭自身程序。
Private Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long
Private Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As Long
Private Sub LimTime()
Dim LastExitTime As String * 255
Dim FirstOpTime As String * 255
Dim RunDays As String * 255
Dim Ret As Long
If Dir("C:\Windows\RunExe.ini") = "" Then
FirstOpTime = Now
LastExitTime = Now
Ret = WritePrivateProfileString("ProgramInfo", "Author", "Cokie", "C:\Windows\RunExe.ini")
Ret = WritePrivateProfileString("ProgramInfo", "FirstOpTime", FirstOpTime, "C:\Windows\RunExe.ini")
Ret = WritePrivateProfileString("RunRecords", "RunDays", "0", "C:\Windows\RunExe.ini")
Ret = WritePrivateProfileString("RunRecords", "LastExitTime", LastExitTime, "C:\Windows\RunExe.ini")
Else
Ret = GetPrivateProfileString("RunRecords", "LastExitTime", "UnFound", LastExitTime, 255, "C:\Windows\RunExe.ini")
If Now <= CDate(LastExitTime) Then
MsgBox "你改变了系统时间,卑鄙!": Unload Me
Else
Ret = GetPrivateProfileString("RunRecords", "RunDays", "UnFound", RunDays, 255, "C:\Windows\RunExe.ini")
If CLng(RunDays) >= 30 Then
MsgBox "您的试用期已经到了!": Unload Me
Else
If Day(CDate(LastExitTime)) <> Day(Now) Then
RunDays = CStr(DateDiff("d", CDate(LastExitTime), Date) + CLng(RunDays))
Ret = WritePrivateProfileString("RunRecords", "Rundays", RunDays, "C:\Windows\RunExe.ini")
End If
End If
End If
End Sub
Private Sub Form_Load()
Call LimTime
End Sub
Private Sub Form_Unload(Cancel As Integer)
Dim LastExitTime As String * 255
LastExitTime = Now
Ret = WritePrivateProfileString("RunRecords", "LastExitTime", LastExitTime, "C:\Windows\RunExe.ini")
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询