Private Declare Function IsPwrHibernateAllowed Lib "powrprof.dll" () As Long
可以判断是否有休眠功能
Private Declare Function SetSuspendState Lib "Powrprof.dll" (ByVal Hibernate As Long, ByVal ForceCritical As Long, ByVal DisableWakeEvents As Long) As Long
可以设定休眠,当参数Hibernate = 1时
Private Declare Function ExitWindowsEx Lib "user32" (ByVal uFlags As Long, _
ByVal dwReserved As Long) As Long
Private Declare Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As Long
Private Declare Function GetTickCount Lib "kernel32" () As Long
Dim mytime As Date
Dim RUNTIME As Long
Private Sub Timer1_Timer()
Dim HOUR As Integer
Dim MIN As Integer
Dim SEC As Integer
Dim RUN As String
Dim delay As Integer
RUNTIME = GetTickCount() \ 1000
HOUR = Int(RUNTIME \ 3600)
MIN = (RUNTIME - 3600 * HOUR) \ 60
SEC = RUNTIME - 3600 * HOUR - 60 * MIN
RUN = HOUR & ":" & MIN & ":" & SEC
Select Case GetSystemMetrics(SM_CLEANBOOT)
Case 1: Label1.Caption = "安全模式已运行" & Format(RUN, "hH:Mm:Ss")
Case 2: Label1.Caption = "网络安全模式已运行" & Format(RUN, "hH:Mm:Ss")
Case Else: Label1.Caption = "正常模式已运行" & Format(RUN, "hH:Mm:Ss")
End Select
delay = (Val(Text1.Text) - RUNTIME \ 60 + mytime \ 60)
If Text1.Enabled = False Then
Label3.Caption = "距离关闭计算机还有 " & delay & " 分钟"
If delay = 0 Then Call ExitWindowsEx(EWX_SHUTDOWN, 0)
End If
End Sub
Private Sub Command1_Click()
If Val(Text1.Text) * 60 > 60 Then
Text1.Enabled = False
mytime = RUNTIME
Else
MsgBox ("请输入关机时间,时间要大于1分钟!")
End If
End Sub
Private Sub Command2_Click()
Text1.Enabled = True
End Sub