pop:其實(shí)實(shí)現(xiàn)自動(dòng)關(guān)機(jī)的核心就是shutdown的命令,at 21:00 shutdown -s 就是在21:00自動(dòng)關(guān)機(jī),會(huì)有30秒的提示;要是沒(méi)有提示直接關(guān)機(jī)就是:at 21:00 shutdown -s -t 0 (注意:要開(kāi)啟“計(jì)劃任務(wù)”的服務(wù)。)
將下面的代碼保存為 *.vbs 后綴的文件,如shutdown.vbs
在輸入時(shí)間或者秒數(shù)之后自動(dòng)關(guān)機(jī),代碼如下:
Dim mytime,myout1,myout2
mytime=null
mytime=InputBox("請(qǐng)輸入定時(shí)時(shí)間(格式23:10:00)"&vblf&"如果想倒計(jì)時(shí)關(guān)機(jī),請(qǐng)輸入倒計(jì)時(shí)時(shí)間"&vblf&"(單位/分鐘)"&vblf&"輸入“pop”可以馬上關(guān)機(jī)"&vblf&"退出點(diǎn)“取消”","定時(shí)關(guān)機(jī)","23:10:00")
Set wshshell=wscript.createobject("wscript.shell")
If IsNumeric(mytime)=False Then
If IsDate(mytime)=True Then
wshshell.run "at "&mytime&" shutdown -s -t 0" '定時(shí)關(guān)機(jī)在任務(wù)列表中
myout1=MsgBox("定時(shí)成功!電腦將在"&mytime&"關(guān)機(jī)!放棄關(guān)機(jī)請(qǐng)點(diǎn)“取消”!",vbokcancel,"定時(shí)關(guān)機(jī)")
If myout1=vbcancel Then
wshshell.run "at /delete /y"
MsgBox "關(guān)機(jī)已取消!",64,"定時(shí)關(guān)機(jī)"
End If
Else
If mytime="pop" Then
wshshell.run "shutdown -s -t 0"
End If
MsgBox "輸入錯(cuò)誤!請(qǐng)重新輸入!",64,"定時(shí)關(guān)機(jī)"
End If
Else
If mytime>600 or mytime<=0 Then
MsgBox "輸入錯(cuò)誤!倒計(jì)時(shí)不能多于10小時(shí)(600分鐘)!",64,"定時(shí)關(guān)機(jī)"
wscript.quit
End If
wshshell.run "shutdown -s -t "&mytime*60
myout2=MsgBox("設(shè)置成功!電腦將在"&mytime&"分鐘后關(guān)機(jī)!放棄關(guān)機(jī)請(qǐng)點(diǎn)“取消”!",vbokcancel,"定時(shí)關(guān)機(jī)")
If myout2=vbcancel Then
wshshell.run "shutdown -a"
MsgBox "關(guān)機(jī)已取消!",64,"定時(shí)關(guān)機(jī)"
End If
End If
這個(gè)比較簡(jiǎn)單,就是實(shí)現(xiàn)倒計(jì)時(shí)關(guān)機(jī)的VBS腳本代碼:
set diaolei=createobject("wscript.shell")
dim shijian,guanji,hua
shijian=time
hua=inputbox("請(qǐng)輸入你要用什么單位關(guān)機(jī) 1 代表分鐘 2 代表小時(shí) 3 代表天")
if hua=1 then
guanji=inputbox("請(qǐng)輸入你要幾分鐘后關(guān)機(jī)")
if datediff("m",shijian,time)>=guanji then
diaolei.run "rundll32.exe user.exe,exitwindows"
diaolei.run "shutdown -s -t 0"
elseif hua=2 then
guanji=inputbox("請(qǐng)輸入你要幾小時(shí)后關(guān)機(jī)")
if datediff("h",shijian,time)>=guanji then
diaolei.run "rundll32.exe user.exe,exitwindows"
diaolei.run "shutdown -s -t 0"
elseif hua=3 then
guanji=inputbox("請(qǐng)輸入你要幾天后關(guān)機(jī)")
if datediff("d",shijian,time)>=guanji then
diaolei.run "rundll32.exe user.exe,exitwindows"
diaolei.run "shutdown -s -t 0"
endif
聯(lián)系客服