由于小弟刚学VB,还不是很精通VB,想写一个VB的定时关机程序,现在的进度是只把定时程序写出来了,但是关机的程序不知道怎么写,希望各位帮帮忙,代码如下:
Private Sub Command1_Click()
Command1.Enabled = False
If Val(Text1) < 1 Or Val(Text1) > 24 Then
MsgBox "小时数输入错误!", vbExclamation, "提示信息"
Text1 = ""
Text1.SetFocus
Command1.Enabled = True
End If
If Val(Text2) < 1 Or Val(Text2) > 60 Then
MsgBox "分钟数输入错误!", vbExclamation, "提示信息"
Text2 = ""
Text2.SetFocus
Command1.Enabled = True
End If
Timer1.Enabled = True
End SubPrivate Sub Command2_Click()
Timer2.Enabled = False
Command1.Enabled = True
If Command1.Enabled = True Then
Timer2.Enabled = True
End If
End Sub
Private Sub Form_Load()
Label2.Caption = Time
Timer1.Interval = 1000
Timer2.Interval = 1000
Command1.Tag = 1
End SubPrivate Sub Timer1_Timer()
Label2.Caption = Time
End SubPrivate Sub Timer2_Timer()
If Command1.Tag = 1 Then
If Val(Text1) = Hour(Now) And Val(Text2) = Minute(Now) Then
MsgBox "时间到!", vbInformation + vcokonly + vbdefault1, "提示"
Command1.Tag = 0
End If
End If
End Sub
Private Sub Command1_Click()
Command1.Enabled = False
If Val(Text1) < 1 Or Val(Text1) > 24 Then
MsgBox "小时数输入错误!", vbExclamation, "提示信息"
Text1 = ""
Text1.SetFocus
Command1.Enabled = True
End If
If Val(Text2) < 1 Or Val(Text2) > 60 Then
MsgBox "分钟数输入错误!", vbExclamation, "提示信息"
Text2 = ""
Text2.SetFocus
Command1.Enabled = True
End If
Timer1.Enabled = True
End SubPrivate Sub Command2_Click()
Timer2.Enabled = False
Command1.Enabled = True
If Command1.Enabled = True Then
Timer2.Enabled = True
End If
End Sub
Private Sub Form_Load()
Label2.Caption = Time
Timer1.Interval = 1000
Timer2.Interval = 1000
Command1.Tag = 1
End SubPrivate Sub Timer1_Timer()
Label2.Caption = Time
End SubPrivate Sub Timer2_Timer()
If Command1.Tag = 1 Then
If Val(Text1) = Hour(Now) And Val(Text2) = Minute(Now) Then
MsgBox "时间到!", vbInformation + vcokonly + vbdefault1, "提示"
Command1.Tag = 0
End If
End If
End Sub
shell "shutdown -s -t 0"
Private Declare Function ExitWindowsEx Lib _
"user32" (ByVal uFlags As Long, _
ByVal dwReserved As Long) As Long
Private Enum HowExitConst
EWX_LOGOFF = 0 '登出
EWX_REBOOT = 2 '重新开机
EWX_SHUTDOWN = 1 '关机
EWX_FORCE = 4 '强制关机
End EnumPrivate Sub Command1_Click() '关机
Call ExitWindowsEx(HowExitConst.EWX_SHUTDOWN, 0)
End Sub
1 = 关机
2 = 重启动
3 = 强制关机,即不通知现在活动应用程序让其先自我关闭