Simple script to reboot and automatically enter BIOS/UEFI

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
YottaByte
Posts: 21
Joined: 14 Oct 2020 13:07
Location: Argentina

Simple script to reboot and automatically enter BIOS/UEFI

#1 Post by YottaByte » 14 May 2025 09:18

Hi everyone.

Download link for the folder with the scripts in Spanish and English:
https://drive.google.com/file/d/1-Yagj- ... sp=sharing

Code: Select all

:: ___________________________________________
::
:: EntBIOS 1.0.1
:: MarcSoft (R)
:: Copyright (C) 2025 Eduardo A. Marclay
:: ___________________________________________

@ECHO OFF
SETLOCAL EnableExtensions EnableDelayedExpansion
	   CLS
	COLOR 1B
	MODE CON COLS=53 LINES=12
:: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ main ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
:: initialize the %noresize% macro
call :init_noresize

:: pass non-zero to disable resizing
%noresize% 1
:: ----------------------------End Main-----------------------------

	TITLE EntBIOS
ECHO  ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
ECHO  ³   Choose the number of minutes to wait before   ³
ECHO  ³  rebooting and automatically entering the BIOS. ³
ECHO  ³ You'll then need to confirm or abort the reboot ³
ECHO  ³ ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ ³
ECHO  ³ (1)Äþ 1 Minute        ³³       (6)Äþ 6  Minutes ³
ECHO  ³ (2)Äþ 2 Minutes       ³³       (7)Äþ 7  Minutes ³
ECHO  ³ (3)Äþ 3 Minutes       ³³       (8)Äþ 8  Minutes ³
ECHO  ³ (4)Äþ 4 Minutes       ³³       (9)Äþ 9  Minutes ³
ECHO  ³ (5)Äþ 5 Minutes       ³³       (0)Äþ 10 Minutes ³
ECHO  ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ

	CHOICE /c 1234567890 /n
	IF ERRORLEVEL 10 SET SEGS=600 & SET MINS=10 & (GOTO INICIO)
	IF ERRORLEVEL 9 SET SEGS=540 & SET MINS=09 & (GOTO INICIO)
	IF ERRORLEVEL 8 SET SEGS=480 & SET MINS=08 & (GOTO INICIO)
	IF ERRORLEVEL 7 SET SEGS=420 & SET MINS=07 & (GOTO INICIO)
	IF ERRORLEVEL 6 SET SEGS=360 & SET MINS=06 & (GOTO INICIO)
	IF ERRORLEVEL 5 SET SEGS=300 & SET MINS=05 & (GOTO INICIO)
	IF ERRORLEVEL 4 SET SEGS=240 & SET MINS=04 & (GOTO INICIO)
	IF ERRORLEVEL 3 SET SEGS=180 & SET MINS=03 & (GOTO INICIO)
	IF ERRORLEVEL 2 SET SEGS=120 & SET MINS=02 & (GOTO INICIO)
	IF ERRORLEVEL 1 SET SEGS=60  & SET MINS=01 & (GOTO INICIO)

:INICIO
	   CLS
ECHO 
	MODE CON COLS=48 LINES=8
	COLOR 4F
	TITLE EntBIOS
set sizemax=44
for /L %%# in (1,2,!sizemax!) do if "!s:~%sizemax%,1!" == "" set "s= !s! "
set s=!s:~1,%sizemax%!
ECHO  ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
ECHO  ³     The PC will restart in %MINS%minutes      ³
ECHO  ³  and will automatically enter BIOS/UEFI.   ³
ECHO  ³         Do you want to continue?           ³
ECHO  ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´
ECHO  ³²²²²² (Y)Ä^> Yes ²²²²²²²²²²²²² (N)Ä^> No ²²²²²³
ECHO  ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ

	CHOICE /c yn /n
	IF ERRORLEVEL 2 GOTO ABORT
	IF ERRORLEVEL 1 GOTO SIGUE

:ABORT
CLS
ECHO 
	MODE CON COLS=48 LINES=6
	TITLE ­ABORT^^!
	COLOR 4F
ECHO  ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
ECHO  ³             ABORTED OPERATION^^!             ³
ECHO  ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´
ECHO  ³²²²²²²²²²²²²²²² (C)Ä^> Close ²²²²²²²²²²²²²²²²³
ECHO  ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ

	CHOICE /c c /n
	IF ERRORLEVEL 1 GOTO SALE

:SIGUE
CD %HOMEDRIVE%\windows\sistem32\
START /MIN shutdown.exe /r /fw /t %SEGS% >nul

:SALE
EXIT
:: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ subroutine ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
:: disable minimizing, maximizing, and resizing of the console window
:init_noresize
setlocal DisableDelayedExpansion
set noresize=for %%i in (1 2) do if %%i==2 (^
%=% for /f %%j in ("^^!arg^^! x") do powershell -nop -ep Bypass -c ^"try{$c=Add-Type -Name pInv -PassThru -MemberDefinition '^
%===% [DllImport(\"kernel32\")] public static extern IntPtr GetConsoleWindow();^
%===% [DllImport(\"user32\")] public static extern int GetWindowLong(IntPtr wnd,int idx);^
%===% [DllImport(\"user32\")] public static extern Int64 GetWindowLongPtr(IntPtr wnd,int idx);^
%===% [DllImport(\"user32\")] public static extern int SetWindowLong(IntPtr wnd,int idx,int newLong);^
%===% [DllImport(\"user32\")] public static extern Int64 SetWindowLongPtr(IntPtr wnd,int idx,Int64 newLong);';^
%===% $flag=0; $mask = 65536 -bOr 262144; $wnd=$c::GetConsoleWindow();^
%===% if(-not [Int32]::TryParse(\"%%~j\",[ref]$flag)){exit 1;}^
%===% if($flag -eq 0){^
%=====% if([IntPtr]::Size -eq 4){$null=$c::SetWindowLong($wnd,-16,$c::GetWindowLong($wnd,-16) -bOr $mask);}^
%=====% else{$null=$c::SetWindowLongPtr($wnd,-16,$c::GetWindowLongPtr($wnd,-16) -bOr [Int64]$mask);}}^
%===% elseif([IntPtr]::Size -eq 4){$null=$c::SetWindowLong($wnd,-16,$c::GetWindowLong($wnd,-16) -bAnd -bNot $mask);}^
%===% else{$null=$c::SetWindowLongPtr($wnd,-16,$c::GetWindowLongPtr($wnd,-16) -bAnd -bNot [Int64]$mask);}}catch{exit 1;}^"^&endlocal^
%=% ) else setlocal EnableDelayedExpansion^&set arg=
endlocal&set "noresize=%noresize%"
if !!# neq # set "noresize=%noresize:^^=%"
exit /b
Eduardo

Aacini
Expert
Posts: 1924
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: Simple script to reboot and automatically enter BIOS/UEFI

#2 Post by Aacini » 14 May 2025 11:11

Hi. I have not tested your code. I just want to note that you can get the same result in a simpler way. Instead of this code:

Code: Select all

	CHOICE /c 1234567890 /n
	IF ERRORLEVEL 10 SET SEGS=600 & SET MINS=10 & (GOTO INICIO)
	IF ERRORLEVEL 9 SET SEGS=540 & SET MINS=09 & (GOTO INICIO)
	IF ERRORLEVEL 8 SET SEGS=480 & SET MINS=08 & (GOTO INICIO)
	IF ERRORLEVEL 7 SET SEGS=420 & SET MINS=07 & (GOTO INICIO)
	IF ERRORLEVEL 6 SET SEGS=360 & SET MINS=06 & (GOTO INICIO)
	IF ERRORLEVEL 5 SET SEGS=300 & SET MINS=05 & (GOTO INICIO)
	IF ERRORLEVEL 4 SET SEGS=240 & SET MINS=04 & (GOTO INICIO)
	IF ERRORLEVEL 3 SET SEGS=180 & SET MINS=03 & (GOTO INICIO)
	IF ERRORLEVEL 2 SET SEGS=120 & SET MINS=02 & (GOTO INICIO)
	IF ERRORLEVEL 1 SET SEGS=60  & SET MINS=01 & (GOTO INICIO)

:INICIO
... you can do the same in this way:

Code: Select all

	CHOICE /c 1234567890 /n
        SET /A MINS=%ERRORLEVEL%, SEGS=MINS * 60
        IF %MINS% LSS 10 SET "MINS= %MINS%"
You can also make good use of arrays.

Antonio

PS - ¿De dónde eres, Eduardo? Yo vivo en México...

YottaByte
Posts: 21
Joined: 14 Oct 2020 13:07
Location: Argentina

Re: Simple script to reboot and automatically enter BIOS/UEFI

#3 Post by YottaByte » 14 May 2025 11:52

Hola, Antonio.

Voy a tener en cuenta tu sugerencia, gracias.

Soy de Argentina. Por cierto, me gusta el folclore mexicano, como suenan esos guitarrones y las trompetas.
Esta es mi ciudad:
https://www.google.com.ar/maps/@-32.484 ... FQAw%3D%3D

Un saludo.
Eduardo.

Post Reply