用VB怎样实现5小时延时,也就是说每5小时从新启动一下电脑。启动自动加载程序,然后5小时又从新启动!

来源:百度知道 编辑:UC知道 时间:2024/06/17 11:51:10

新建工程,添加timer控件,添加代码:

Private t As Integer
Private Sub Form_Load()
Timer1.Interval = 60000
Me.Visible = False
End Sub

Private Sub Timer1_Timer()
t = t + 1
If t = 300 Then
Shell "cmd.exe /c shutdown -r -f"
End If
End Sub

生成工程,把其放在启动目录下..重启..OK!

XP的启动目录:C:\Documents and Settings\All Users\「开始」菜单\程序\启动

Visa的启动目录:C:\Users\Administrator\AppData\Roaming\Microsoft\Windows\Start Menu\Programs

定义一个时间变量,在启动时为其赋当前时间值
用timer控件,每隔一段时间查一下(建议一分钟)当前时间值与上面定义的时间变量之差是否为5小时,如大于5,则延时5小时事件发生.

当然,如要精确度高一点,也可以一秒检查一次

Public A As Integer
Private Sub Form_Load()
Timer1.Interval = 60000
End Sub
Private Sub Timer1_Timer()
A = A + 1
If A = 300 Then
A = 0
你启动电脑调用的代码
End If

End Sub

用timer控件
Option Explicit
Dim intTime As Integer
Private Sub Form_Load