VB获取网络时间

用VB做了个收费软件。想限制使用30天,用了下面这段代码:PrivateSubForm_Load()DimregstrAsStringregstr=GetSetting(... 用VB做了个收费软件。想限制使用30天,用了下面这段代码:Private Sub Form_Load()
Dim regstr As Stringregstr = GetSetting("expire", "startdate", "date", "notexist")
If regstr = "notexist" Then 'record did not exist in regedit
SaveSetting "expire", "startdate", "date", Date
ElseIf DateDiff("d", CDate(regstr), Date) >= 30Then

MsgBox "您的使用期已到,请继续充值!",64,""
End
End If
End If
End Sub
'存在注册表中:[HKEY_CURRENT_USER\Software\VB and VBA Program Settings\expire\startdate]我试了下把系统时间改成2009年的话软件就显示有300多天了, 所以我想获取网络时间来限制软件的使用期!还有上面这段代码帮我改一下,我不想存在注册表里,电脑重装就没了!存在D盘里,当软件第一次运行时就获取当前的网络时间并保存在D盘里!然后下次运行就获取网络时间来判断第一次运行的时间算出剩余时间!
展开
 我来答
匿名用户
2013-07-21
展开全部
可以禁止修改系手慧纳统时间即可,代码如下,源码可以发给你,你的邮箱是?窗体form1(需要一个timer控件,毕没interval=1000):
窗体代码碧裂Private Sub Form_Load()
Timer1_Timer
RegisterWindow Me.hwnd '为窗口设置子类
End SubPrivate Sub Form_Unload(Cancel As Integer)
unRegisterWindow Me.hwnd '取消窗口的子类
End SubPrivate Sub Timer1_Timer()
OldTime = Now
End Sub'模块modle1:Option Explicit
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Public Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Public Declare Function RegisterWindowMessage Lib "user32" Alias "RegisterWindowMessageA" (ByVal lpString As String) As Long
Public OldTime As String
Public ChangeFlag As Boolean
Public Const WM_TIMECHANGE As Long = &H1E '当系统的时间变化时发送此消息给所有顶级窗口
Public oldproc As Long
Private Type SYSTEMTIME
wYear As Integer
wMonth As Integer
wDayOfWeek As Integer
wDay As Integer
wHour As Integer
wMinute As Integer
wSecond As Integer
wMilliseconds As Integer
End Type
Private Declare Function SetLocalTime Lib "kernel32" (lpSystemTime As SYSTEMTIME) As LongPublic Function RegisterWindow(hwnd As Long) As Long
If hwnd <> 0 Then
oldproc = SetWindowLong(hwnd, -4, AddressOf WinProc)
End If
End Function
Public Function unRegisterWindow(hwnd As Long) As LongIf hwnd <> 0 Then
SetWindowLong hwnd, -4, oldproc
End IfEnd Function
Public Function WinProc(ByVal hwnd As Long, ByVal msg As Long, ByVal lpara As Long, ByVal wpara As Long) As LongDim i, myttIf msg = WM_TIMECHANGE And ChangeFlag = False Then '系统时间被修改了而且不是本程序修改的ChangeFlag = True '本程序要修改系统时间Call SetToOldTime '修改系统时间Exit FunctionEnd If
ChangeFlag = FalseWinProc = CallWindowProc(oldproc, hwnd, msg, lpara, wpara)
End Function
Public Function SetToOldTime() As String '将时间恢复到设置前的状态
Dim tmp As String
tmp = OldTime '从保存的时间中取出修改前的系统时间
Dim lpSystemTime As SYSTEMTIME
lpSystemTime.wYear = Year(tmp) '取出年份
lpSystemTime.wMonth = Month(tmp) '取出月份
lpSystemTime.wDayOfWeek = -1
lpSystemTime.wDay = Day(tmp) '取出日
lpSystemTime.wHour = Hour(tmp) '取出小时
lpSystemTime.wMinute = Minute(tmp) '取出分钟
lpSystemTime.wSecond = Second(tmp) '取出秒
lpSystemTime.wMilliseconds = 0
'set the new time
SetLocalTime lpSystemTimeEnd Function
匿名用户
2013-07-21
展开全部
想问下你的软件是不是一定兄戚要在Int环境下运行态让的帆尘局。如果是的话。那就简单了说。网络注册就行了。若是单机环境可运行的话。建议注册表加主程序注册来控制。
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式