winreboot.bat
::Author: DaiWei
::Version 1.1
::修改日期:July 3rd,2018
::修改日志:
:: 1.增加了自动取消登录界面的功能,并在停止时自动打开
:: 2.增加自动关闭出错重启,并在停止时自动再次打开
:: 3.双击此脚本执行reboot,系统会检测cpu、disk,NIC和memory,遇错会自动停止
:: 4.在执行reboot后,脚本会自动在桌面创建一个stop_wreboot.bat的脚本,需要停止reboot时双击此脚本即可
@echo off
:_Start
::----------------------------------------
::Script Start Here
::----------------------------------------
SET locate_startup="C:\Users\Administrator\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup"
SET locate_Desktop=C:\Users\Administrator\Desktop
call:_Check_DISK
call:_Check_CPU
call:_Check_MEMORY
call:_Check_NetworkCard
call:_Reboot
if not exist %locate_startup%\wreboot.bat (call:_Prepare) else (call:_Compare)
GOTO:EOF
::----------------------------------------
::Function Section Start Below Here
::----------------------------------------
:_Prepare -准备第一次重启,并生成Stop_wreboot.bat文件
copy %~dp0wreboot.bat %locate_startup%
call:_Create_Stop_Reboot
call:_SET_AutoLogon
call:_SET_NoAutoReboot
move MEMORY_AFTER.txt MEMORY_BASIC.txt
move DISK_AFTER.txt DISK_BASIC.txt
move CPU_AFTER.txt CPU_BASIC.txt
move NIC_AFTER.txt NIC_BASIC.txt
echo The reboot started at %date% %time% > %locate_Desktop%\reboot_all_log.txt
GOTO:EOF
:_Check_CPU
::获取CPU的名称、外频、状态、描述、最大时钟频率、设备号
wmic cpu get name ,ExtClock ,CpuStatus ,Description ,MaxClockSpeed ,DeviceID /value > %locate_Desktop%\CPU_AFTER.txt
GOTO:EOF
:_Check_DISK
::获取硬盘的描述、接口类型、大小、分区个数、分区描述、分区设备号(盘符)、分区文件系统、分区大小
wmic DISKDRIVE get model ,interfacetype ,size ,locate_startuprtitions /value >%locate_Desktop%\DISK_AFTER.txt
wmic LOGICALDISK where mediatype='12' get description,deviceid,filesystem,size /value >>%locate_Desktop%\DISK_AFTER.txt
GOTO:EOF
:_Check_MEMORY
::获取内存的BankLabel、名称、位置、容量、频率
wmic MEMORYCHIP get BankLabel ,Name ,DeviceLocator ,Capacity ,speed /value >%locate_Desktop%\MEMORY_AFTER.txt
::systeminfo |find "Total Physical Memory:">%locate_Desktop%\MEMORY_AFTER.txt
GOTO:EOF
:_Check_NetworkCard
::获取网卡的设备类型、描述、设备号、MAC地址、名称、速率
wmic nic where PhysicalAdapter='TRUE' get AdapterType ,Description ,DeviceID ,MACAddress ,Name ,Speed /value >%locate_Desktop%\NIC_AFTER.txt
GOTO:EOF
:Create_Stop_Reboot
::停止reboot并删除startup下的reboot脚本
echo shutdown -a >%locate_Desktop%\stop_wreboot.bat
echo del %locate_startup%wreboot.bat >>%locate_Desktop%\stop_wreboot.bat
::停止reboot时删除自动登录
echo reg delete "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" /v AutoAdminLogon /f >>%locate_Desktop%\stop_wreboot.bat
echo reg delete "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" /v DefaultUserName /f >>%locate_Desktop%\stop_wreboot.bat
echo reg delete "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" /v DefaultPassword /f >>%locate_Desktop%\stop_wreboot.bat
::停止reboot时打开windows出错自动重启
echo wmic recoveros set AutoReboot = True >>%locate_Desktop%\stop_wreboot.bat
echo md %locate_Desktop%\reboot_logs >>%locate_Desktop%\stop_wreboot.bat
echo echo the reboot stoped at %%date%%%%time%% >> %locate_Desktop%\reboot_all_log.txt >>%locate_Desktop%\stop_wreboot.bat
echo for %%%%i in ^(%locate_Desktop%\NIC_BASIC.txt %locate_Desktop%\NIC_AFTER.txt %locate_Desktop%\MEMORY_BASIC.txt %locate_Desktop%\MEMORY_AFTER.txt %locate_Desktop%\CPU_BASIC.txt %locate_Desktop%\CPU_AFTER.txt %locate_Desktop%\DISK_BASIC.txt %locate_Desktop%\DISK_AFTER.txt %locate_Desktop%\reboot_all_log.txt %locate_Desktop%\reboot_all_times.txt^) do move %%%%i %locate_Desktop%\reboot_logs >>%locate_Desktop%\stop_wreboot.bat
echo del %locate_Desktop%\stop_wreboot.bat >>%locate_Desktop%\stop_wreboot.bat
GOTO:EOF
:_Reboot
for /f %%i in (%locate_Desktop%\reboot_all_times.txt) do set count=%%i
set /a count+=1
echo %count% >%locate_Desktop%\reboot_all_times.txt
echo the %count% times reboot at %date% %time% with no error >>%locate_Desktop%\reboot_all_log.txt
shutdown -r -t 60
GOTO:EOF
:_Compare
FC %locate_Desktop%\CPU_BASIC.txt %locate_Desktop%\CPU_AFTER.txt && FC %locate_Desktop%\DISK_BASIC.txt %locate_Desktop%\DISK_AFTER.txt && FC %locate_Desktop%\MEMORY_BASIC.txt %locate_Desktop%\MEMORY_AFTER.txt && FC %locate_Desktop%\NIC_BASIC.txt %locate_Desktop%\NIC_AFTER.txt
if not %ERRORLEVEL% 0 (GOTO:_Error_Issue)
GOTO:EOF
:_Error_Issue
echo the %count% times reboot at %date% %time% with some errors,and the reboot stoped,please check the logs >>%locate_Desktop%\reboot_all_log.txt
call %locate_Desktop%\stop_wreboot
GOTO:EOF
:_SET_AutoLogon
::设置自动登录,默认用户名为Administrator,密码为1q ::若使用其他用户名密码,请在下列修改 set UserName=Administrator set Passwd=
1q
::设置自动登录的用户名
reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" /v DefaultUserName /t REG_SZ /d %UserName% -f
::设置自动登录的密码
reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" /v DefaultPassword /t REG_SZ /d %Passwd% -f
::设置自动登录生效
reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" /v AutoAdminLogon /t REG_SZ /d 1 -f
GOTO:EOF
:_SET_NoAutoReboot
::关闭windows出错自动重启
wmic recoveros set AutoReboot = False