@echo off

REM mbrwiz.cmd
REM Created by Kalonji
REM Version 1.0a

setlocal

%~d0
cd "%~dp0"

:_tsk
title MBRWizard
set _task=
cls
echo What do you want to do?
echo.
echo  1: List MBR entries
echo  2: Hide partition(s)
echo  3: Unhide partition(s)
echo  4: Activate partition
echo  5: Inactivate partition(s)
echo  6: Delete partition
echo  7: Wipe MBR or first 63 sectors of disk
echo  8: Save MBR to file
echo  9: Restore MBR from file
echo 10: Show contents of saved MBR file
echo 11: Sort MBR entries by disk location
echo.
echo Press [ENTER] to exit
echo.
set /p _task=Enter task:
echo.
if "%_task%" == "" goto _ext
cls
if "%_task%" == "1" goto _lst
if "%_task%" == "2" goto _hde
if "%_task%" == "3" goto _unhde
if "%_task%" == "4" goto _actv
if "%_task%" == "5" goto _inactv
if "%_task%" == "6" goto _del
if "%_task%" == "7" goto _wpe
if "%_task%" == "8" goto _sav
if "%_task%" == "9" goto _rstr
if "%_task%" == "10" goto _shw
if "%_task%" == "11" goto _issrt

:_lst
title MBRWizard - List MBR entries
echo 1: List MBR entries
echo.
echo Running: mbrwiz.exe /list
echo.
mbrwiz.exe /list
echo.
pause
goto _tsk

:_hde
title MBRWizard - Hide partition(s)
set _disk=
set _part=
echo 2: Hide partition(s)
echo.
echo Please enter the HDD to use ("0" for 1st, "1" for 2nd, ...)
echo.
echo Press [ENTER] to abort.
echo.
set /p _disk=Enter disk:
if "%_disk%" == "" goto _ext
echo.
echo Please enter the partition ID to hide ("0" for 1st,
echo "1" for 2nd, ...; "*" for all).
echo.
echo Press [ENTER] to abort.
echo.
set /p _part=Enter partition:
if "%_part%" == "" goto _ext
echo.
cls
echo Running: mbrwiz.exe /disk=%_disk% /hide=%_part% /list
echo.
mbrwiz.exe /disk=%_disk% /hide=%_part% /list
if "%errorlevel%" == "0" goto _sccss
echo.
goto _ext

:_unhde
title MBRWizard - Unhide partition(s)
set _disk=
set _part=
echo 3: Unhide partition(s)
echo.
echo Please enter the HDD to use ("0" for 1st, "1" for 2nd, ...)
echo.
echo Press [ENTER] to abort.
echo.
set /p _disk=Enter disk:
if "%_disk%" == "" goto _ext
echo.
echo Please enter the partition ID to unhide ("0" for 1st,
echo "1" for 2nd, ...; "*" for all).
echo.
echo Press [ENTER] to abort.
echo.
set /p _part=Enter partition:
if "%_part%" == "" goto _ext
echo.
cls
echo Running: mbrwiz.exe /disk=%_disk% /unhide=%_part% /list
echo.
mbrwiz.exe /disk=%_disk% /unhide=%_part% /list
if "%errorlevel%" == "0" goto _sccss
echo.
goto _ext

:_actv
title MBRWizard - Activate partition(s)
set _disk=
set _part=
echo 4: Activate partition
echo.
echo Please enter the HDD to use ("0" for 1st, "1" for 2nd, ...)
echo If you don't know which HDD to choose, you can enter "menu" for bootmenu.
echo.
echo Press [ENTER] to abort.
echo.
set /p _disk=Enter disk:
if "%_disk%" == "" goto _ext
if "%_disk%" == "menu" goto _bm
echo.
echo Please enter the partition ID to activate ("0" for 1st, "1" for 2nd, ...).
echo.
echo Press [ENTER] to abort.
echo.
set /p _part=Enter partition:
if "%_part%" == "" goto _ext
echo.
cls
echo Running: mbrwiz.exe /disk=%_disk% /active=%_part% /list
echo.
mbrwiz.exe /disk=%_disk% /active=%_part% /list
if "%errorlevel%" == "0" goto _sccss
echo.
goto _ext

:_bm
cls
echo Running: mbrwiz.exe /bootmenu
echo.
mbrwiz.exe /bootmenu
echo.
if "%errorlevel%" == "0" goto _sccss
echo.
goto _ext

:_inactv
title MBRWizard - Inactivate partition(s)
set _disk=
set _part=
echo 5: Inactivate partition(s)
echo.
echo Please enter the HDD to use ("0" for 1st, "1" for 2nd, ...)
echo.
echo Press [ENTER] to abort.
echo.
set /p _disk=Enter disk:
if "%_disk%" == "" goto _ext
echo.
echo Please enter the partition ID to inactivate ("0" for 1st,
echo "1" for 2nd, ...; "*" for all).
echo.
echo Press [ENTER] to abort.
echo.
set /p _part=Enter partition:
if "%_part%" == "" goto _ext
echo.
cls
echo Running: mbrwiz.exe /disk=%_disk% /inactive=%_part% /list
echo.
mbrwiz.exe /disk=%_disk% /inactive=%_part% /list
if "%errorlevel%" == "0" goto _sccss
echo.
goto _ext

:_del
title MBRWizard - Delete partition
set _disk=
set _part=
echo 6: Delete partition
echo.
echo Please enter the HDD to use ("0" for 1st, "1" for 2nd, ...)
echo.
echo Press [ENTER] to abort.
echo.
set /p _disk=Enter disk:
if "%_disk%" == "" goto _ext
echo.
echo Please enter the partition ID to delete ("0" for 1st, "1" for 2nd, ...).
echo.
echo Press [ENTER] to abort.
echo.
set /p _part=Enter partition:
if "%_part%" == "" goto _ext
echo.
cls
echo Running: mbrwiz.exe /disk=%_disk% /del=%_part% /list
echo.
mbrwiz.exe /disk=%_disk% /del=%_part% /list
goto _ext

:_wpe
title MBRWizard - Wipe MBR or first 63 sectors of disk
set _disk=
set _opt=
echo 7: Wipe MBR or first 63 sectors of disk
echo.
echo Please enter the HDD to use ("0" for 1st, "1" for 2nd, ...)
echo.
echo Press [ENTER] to abort.
echo.
set /p _disk=Enter disk:
if "%_disk%" == "" goto _ext
echo.
echo Please enter "1" for wipe of MBR, "2" for wipe of first 63 sectors.
echo.
echo Press [ENTER] to abort.
echo.
set /p _opt=Enter option:
if "%_opt%" == "" goto _ext
echo.
cls
echo Running: mbrwiz.exe /disk=%_disk% /wipe=%_opt% /list
echo.
mbrwiz.exe /disk=%_disk% /wipe=%_opt% /list
goto _ext

:_sav
title MBRWizard - Save MBR to file
set _disk=
set _file=
echo 8: Save MBR to file
echo.
echo Please enter the HDD to use ("0" for 1st, "1" for 2nd, ...)
echo.
echo Press [ENTER] to abort.
echo.
set /p _disk=Enter disk:
if "%_disk%" == "" goto _ext
echo.
echo Please enter filename to save (eg: a:\hdd0.mbr)
echo.
echo Press [ENTER] to abort.
echo.
set /p _file=Enter filename:
if "%_file%" == "" goto _ext
echo.
cls
echo Running: mbrwiz.exe /disk=%_disk% /save=%_file%
echo.
mbrwiz.exe /disk=%_disk% /save=%_file%
echo.
goto _ext

:_rstr
title MBRWizard - Restore MBR from file
set _disk=
set _file=
echo 9: Restore MBR from file
echo.
echo Please enter the HDD to use ("0" for 1st, "1" for 2nd, ...)
echo.
echo Press [ENTER] to abort.
echo.
set /p _disk=Enter disk:
if "%_disk%" == "" goto _ext
echo.
echo Please enter filename to restore (eg: a:\hdd0.mbr)
echo.
echo Press [ENTER] to abort.
echo.
set /p _file=Enter filename:
if "%_file%" == "" goto _ext
echo.
cls
echo Running: mbrwiz.exe /disk=%_disk% /restore=%_file% /list
echo.
mbrwiz.exe /disk=%_disk% /restore=%_file% /list
echo.
goto _ext

:_shw
title MBRWizard - Show contents of saved MBR file
set _file=
echo 10: Show contents of saved MBR file
echo.
echo Please enter filename to display (eg: a:\hdd0.mbr)
echo.
echo Press [ENTER] to abort.
echo.
set /p _file=Enter filename:
if "%_file%" == "" goto _ext
echo.
cls
echo Running: mbrwiz.exe /showfile=%_file%
echo.
mbrwiz.exe /showfile=%_file%
goto _ext

:_issrt
title MBRWizard - Sort MBR entries by disk location
echo 11: Sort MBR entries by disk location
echo.
echo Running: mbrwiz.exe /issorted /list
echo.
mbrwiz.exe /issorted /list
if "%errorlevel%" == "1" goto _srt
echo The partition entries in MBR are already sorted.
goto _ext

:_srt
set _inp=
echo The partition entries in MBR are not sorted.
echo Do you want MBRWizard to sort the partition entries?
echo.
echo Press [ENTER] to abort.
echo.
set /p _inp=Enter [Y]es or [N]o:
echo.
if /I "%_inp%" == "" goto _ext
if /I "%_inp%" == "n" goto _ext
REM echo.
cls
echo Running: mbrwiz.exe /sort /list
echo.
mbrwiz.exe /sort /list
if "%errorlevel%" == "0" goto _sccss
goto _ext

:_sccss
echo Operation completed successfully.
echo.
goto _ext

:_ext
set _exit=
echo.
echo Do you want to exit?
echo.
set /p _exit=Enter [Y]es or [N]o:
if /I "%_exit%" == "" goto _ext
if /I "%_exit%" == "n" goto _tsk
if /I "%_exit%" == "y" goto _end

:_end
endlocal