Private Declare Function GetTickCount Lib 'kernel32' () As Long' 此函数的作用是获得系统运行了多少时间(运行了多久),单位是毫秒 'MSDN原文:The GetTickCount function retrieves the number of milliseconds that have elapsed since the system was started.
Private Type LASTINPUTINFO cbSize As Long dwTime As Long End Type Dim lii As LASTINPUTINFO
Private Sub Form_Load() Timer1.Interval = 1000 lii.cbSize = Len(lii)' '看API声明,API里要求这个变量的cbSize保存为这个变量的长度,这样才可以被API正确操作 End Sub
Private Sub Timer1_Timer() '如果是Access中使用,请改为Form_Timer事件,且设置定时器间隔属性为1000毫秒--Office中国提醒 If GetLastInputInfo(lii) Then If (GetTickCount - lii.dwTime) / 60000 >= 15 Then Shell 'shutdown.exe -s -t 180' Call MsgBox('由于本机15分钟没有操作,如果3分钟后没有反应,系统将强制关机', vbYesNo + vbExclamation + vbDefaultButton2, '提示') End If End If End Sub