求每天定时关机的VB代码?
求每天定时关机的VB代码?必须能设置每天定时关机,最好是完整版的代码。如果很满意的话可以加到500分
补充:请问一楼二楼是每天定时关机吗?
求每天定时关机的VB代码?必须能设置每天定时关机,最好是完整版的代码。如果很满意的话可以加到500分
补充:请问一楼二楼是每天定时关机吗?
答案:很简单的,新建一个窗体,画一个timer控件,将interval设为1000,假设你希望每天的晚上8点关电脑,则直接在代码区写上以下代码
const t as string="20:00" '修改关机时间请在这里修改,
private sub form_load()
me.visible=false
timer1.interval=1000
end sub
private sub timer1_timer()
if time(now)=t then
shell "shutdown -s -f -t 1"
end if
end sub
以上为代码,哪里不懂请追问
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As LongPrivate Sub Form_Load()
'设置程序
Timer1.Interval = 10
Timer1.Enabled = False
For I = 0 To 59
If I < 24 Then Combo1.AddItem I
Combo2.AddItem I
Next
'带命令行"-HT"时后台运行
If UCase(Command) = "-HT" Then
On Error GoTo ERR
MsgBox "程序已在后台运行!按F12呼出/应藏窗体!"
App.TaskVisible = False
Me.Visible = False
H = WshShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Poetry Rain\" & App.Title & "\H")
M = WshShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Poetry Rain\" & App.Title & "\M")
Combo1.ListIndex = H
Combo2.ListIndex = M
Timer1.Enabled = True
End If
Exit Sub
ERR:
MsgBox "时间信息丢失!", 16
End SubPrivate Sub Command1_Click()
On Error Resume Next
If Check1.Value = 1 Then
'导入注册表,实现开机自动运行
Set w = CreateObject("wscript.shell")
w.regwrite "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run\" & App.EXEName, App.Path & "\" & App.EXEName & ".exe -HT"
Else
'删除注册表,取消自动运行
Set w = CreateObject("wscript.shell")
w.regdelete "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run\" & App.EXEName
End If
Set w = CreateObject("wscript.shell")
w.regwrite "HKEY_LOCAL_MACHINE\SOFTWARE\Poetry Rain\" & App.Title & "\H", Combo1
w.regwrite "HKEY_LOCAL_MACHINE\SOFTWARE\Poetry Rain\" & App.Title & "\M", Combo2
MsgBox "定时关机已设置!", 64
Timer1.Enabled = True
End SubPrivate Sub Timer1_Timer()
Static SF As Boolean '记录是否释放F12,以免窗体闪烁
If GetAsyncKeyState(vbKeyF12) Then
If SF = True Then
SF = False
Form1.Visible = Not Form1.Visible
End If
Else
SF = True
End If
'判断时间
H = Hour(Time)
M = Minute(Time)
If Combo1.ListIndex = H And Combo2.ListIndex = M Then
Shell "SHUTDOWN -S -T 60 -C 定时关机时间已到,将在60秒后关机 "
End
End If
End Sub'-----------------------------------------------------------------------------------------------
本代码是程序自身在倒计时,时间到触发60秒关机,可以改为立即(0秒)关机,这样的好处是防止用 SHUTDOWN -A 取消关机计划;程序生成后可以随时更改关机时间!
需要的控件:
ComboBOX两个,设置时,分;Checkbox一个设置是否自动运行;timer一个倒计时和呼出/隐藏窗体!
我的答案超简单:shell“cmd /c at 22:00 Shutdown -s” 简单实用,我不介意你给500分,呵呵…(上面22:00改为你关机的时间)这样写: dim thour as integer,tminute as integer sub form_load() me.visible=false app.taskvisible=false timer1.interval=30000 end sub sub timer1_timer() '待续…
上一个:VB中有没有进制互转函数呢?
下一个:用VB做个倒计时的软件