1.Reboot重启脚本(reboot.bat):
@echo off
setlocal
cd/d %temp%
echo [version] > reboot.inf
set inf=InstallHinfSection DefaultInstall
echo signature=$chicago$ >> reboot.inf
echo [defaultinstall] >> reboot.inf
rundll32 setupapi,%inf% 1 %temp%\reboot.inf
del reboot.inf

2.关机脚本(shutdown.bat):
@echo off
setlocal
cd/d %temp%
echo Set colOperatingSystems = GetObject(“winmgmts:{(Shutdown)}”).ExecQuery(“Select * from Win32_OperatingSystem”) >shutdown.vbs
echo For Each objOperatingSystem in colOperatingSystems >>shutdown.vbs
echo ObjOperatingSystem.Win32Shutdown(8) >>shutdown.vbs
echo Next >>shutdown.vbs
cscript shutdown.vbs
del shutdown.vbs

3.关机脚本(shutdown1.vbs):
Set colOperatingSystems = GetObject(“winmgmts:{(Shutdown)}”).ExecQuery(“Select * from Win32_OperatingSystem”)
For Each objOperatingSystem in colOperatingSystems
    ObjOperatingSystem.Win32Shutdown(8)
Next

4.延时60秒,在关机前提示,可以在延时到达前取消关机(shutdown2.vbs脚本):
set wshshell = CreateObject(“WScript.Shell”)
timeout = 60
‘Time Out 可以自己定义
ask = “系统将在 ” & timeout & ” 秒钟后关机!”
title = “自动关机提示”
constants = vbExclamation + vbOkCancel
result = wshshell.Popup(ask, timeout, title, constants)
if result = vbCancel then
elseif result = true then
Set colOperatingSystems = GetObject(“winmgmts:{(Shutdown)}”).ExecQuery(“Select * from Win32_OperatingSystem”)
For Each objOperatingSystem in colOperatingSystems
ObjOperatingSystem.Win32Shutdown(8)
Next
end if

自从家里用了液晶电视后,PC就装了MCE连液晶观看电影,几个月下来,更新了一些补丁,安装的程序也多了,关机居然关不了,重新装系统吧,也挺烦的,今天写了个批处理,效果还不错,结合MCE遥控器,又可以躺在床上关机了。

方法:

在桌面新建poweroff.bat,内容如下:

tskill explorer                           //杀死explorer进程,可以写成tskill [PID],但是explorer每次开机PID都不一样,因此干脆用进程名explorer

shutdown -s -f -t 00               //不给提示立即强行关机,-s是关闭本地计算机,-f是强行关闭正在使用的其他程序 -t是在几秒内关机,我这写着00是立马关机之意!