请问VB如何禁止修改系统时间?

以及如何解禁?先谢谢啦... 以及如何解禁?先谢谢啦 展开
 我来答
百度网友551ef16c9
2007-09-22 · TA获得超过399个赞
知道小有建树答主
回答量:372
采纳率:0%
帮助的人:361万
展开全部
程序运行时修改时间无效:
窗体、一个Timer1
Private Sub Form_Load()
Me.Timer1.Interval = 1000
Timer1_Timer
RegisterWindow Me.hwnd '为窗口设置子类
End Sub

Private Sub Timer1_Timer()
OldTime = Now
End Sub
模块
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 Long

Public 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 Long

If hwnd <> 0 Then
SetWindowLong hwnd, -4, oldproc
End If

End Function
Public Function WinProc(ByVal hwnd As Long, ByVal msg As Long, ByVal lpara As Long, ByVal wpara As Long) As Long

Dim i, mytt

If msg = WM_TIMECHANGE And ChangeFlag = False Then '系统时间被修改了而且不是本程序修改的

ChangeFlag = True '本程序要修改系统时间

Call SetToOldTime '修改系统时间

Exit Function

End If

ChangeFlag = False

WinProc = 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 lpSystemTime

End Function
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

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

类别

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

说明

0/200

提交
取消

辅 助

模 式