Saturday, February 7, 2015

Save, Restore, Repair MBR using MBRwizard CLI

  • Download MBRwizard CLI from : Click Here
  • For MBRWizard examples : Click Here
  • Save below script as 1mbrwiz.cmd and Execute  It:

REM------------- BEGIN 1mbrwiz.cmd codes -----------------------

@echo off

rem 1mbrwiz.cmd
rem To backup the MBR using %MBRWIZFILE%

setlocal
%~d0
cd "%~dp0"
set OPTION=mbr
set MBRWIZFILE=mbrwiz64.exe
if not exist %MBRWIZFILE% goto _ERROR1

:MENU
title MBRWizard Menu
set _choice=
cls
echo.
echo *********************************************
echo Please select which MBRWizard options to run
echo *********************************************
echo.
echo 1 List MBR entries
echo 2 Hides the Partition number
echo 3 Unhides the Partition number
echo 4 Activates the Partition
echo 5 De-activates the Partition number
echo 6 Deletes the partition
echo 7 Wipes the MBR or wipes the first 63 sectors of disk
echo 8 Saves the MBR to filename
echo 9 Reads and restores the Disk MBR from filename
echo 10 Shows contents of an existing MBR backup file
echo 11 Sort MBR Entries by disk location
echo 12 Repair MBR for Win7 OS for input disk
echo 13 Writes detailed disk and partition information

echo.
echo Press [ENTER] to exit
echo.
echo.
set /p _choice="Enter choice number: "
echo.
if "%_choice%" == "" goto EXIT
cls
if "%_choice%" == "1" goto ListMBR
if "%_choice%" == "2" goto HidePartition
if "%_choice%" == "3" goto UnhidePartition
if "%_choice%" == "4" goto ActivatePartition
if "%_choice%" == "5" goto InactivatePartition
if "%_choice%" == "6" goto DeletePartition
if "%_choice%" == "7" goto WipeMBR
if "%_choice%" == "8" goto SaveMBR
if "%_choice%" == "9" goto RestoreMBR
if "%_choice%" == "10" goto ShowMBR
if "%_choice%" == "11" goto SortMBR
if "%_choice%" == "12" goto RepairMBR
if "%_choice%" == "13" goto Writesini


:Writesini
title MBRWizard -     Writes detailed disk and partition information to filename in a .ini format.
set DriveNumber=
set Filename=
echo.
echo Please enter the HDD to use ("0" for 1st, "1" for 2nd, ...)
echo.
echo Press [ENTER] to abort.
echo.
set /p DriveNumber="Enter drive number: "
if "%DriveNumber%" == "" goto EXIT
set Filename=hd%DriveNumber%.ini
echo.
echo Running: %MBRWIZFILE% /disk=%DriveNumber% /Writeini /filename=%Filename%
echo.
%MBRWIZFILE% /disk=%DriveNumber% /Writeini /filename=%Filename%
if "%errorlevel%" == "0" goto SUCCESS
echo.
goto EXIT

:RepairMBR
title MBRWizard - Repair MBR for Win7 OS for input disk
echo.
set DriveNumber=
echo.
echo Please enter the HDD to use ("0" for 1st, "1" for 2nd, ...)
echo.
echo Press [ENTER] to abort.
echo.
set /p DriveNumber="Enter drive number: "
echo.
if "%DriveNumber%" == "" goto EXIT
echo.
echo Running: %MBRWIZFILE% /disk=%DriveNumber% /repair=win7
echo.
%MBRWIZFILE% /disk=%DriveNumber% /repair=win7
if "%errorlevel%" == "0" goto SUCCESS
echo.
goto EXIT

:ListMBR
title MBRWizard - List MBR entries
echo.
echo Running: %MBRWIZFILE% /list
echo.
%MBRWIZFILE% /list
echo.
goto EXIT

:HidePartition
title MBRWizard - Hides the Partition number
set DriveNumber=
set PartitionNumber=
echo.
echo Please enter the HDD to use ("0" for 1st, "1" for 2nd, ...)
echo.
echo Press [ENTER] to abort.
echo.
set /p DriveNumber="Enter drive number: "
if "%DriveNumber%" == "" goto EXIT
echo.
echo Please enter the partition ID to hide ("0" for 1st,
echo "1" for 2nd, ... or "*" for all).
echo.
echo Press [ENTER] to abort.
echo.
set /p PartitionNumber="Enter partition number to hide: "
if "%PartitionNumber%" == "" goto EXIT
echo.
cls
echo Running: %MBRWIZFILE% /disk=%DriveNumber% /part=%PartitionNumber% /hide /list
echo.
%MBRWIZFILE% /disk=%DriveNumber% /part=%PartitionNumber% /hide /list
if "%errorlevel%" == "0" goto SUCCESS
echo.
goto EXIT

:UnhidePartition
title MBRWizard - Unhides the Partition number
set DriveNumber=
set PartitionNumber=
echo.
echo Please enter the HDD to use ("0" for 1st, "1" for 2nd, ...)
echo.
echo Press [ENTER] to abort.
echo.
set /p DriveNumber="Enter drive number: "
if "%DriveNumber%" == "" goto EXIT
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 PartitionNumber="Enter partition number: "
if "%PartitionNumber%" == "" goto EXIT
echo.
cls
echo Running: %MBRWIZFILE% /disk=%DriveNumber% /part=%PartitionNumber% /unhide  /list
echo.
%MBRWIZFILE% /disk=%DriveNumber% /part=%PartitionNumber% /unhide /list
if "%errorlevel%" == "0" goto SUCCESS
echo.
goto EXIT

:ActivatePartition
title MBRWizard - Activates the Partition
set DriveNumber=
set PartitionNumber=
echo.
echo Please enter the HDD to use ("0" for 1st, "1" for 2nd, ...)
echo If you do not know which HDD to choose, please enter
echo 'bm' to call the bootmenu.
echo.
echo Press [ENTER] to abort.
echo.
set /p DriveNumber="Enter drive number: "
if "%DriveNumber%" == "" goto EXIT
if "%DriveNumber%" == "bm" goto BOOTMENU
echo.
echo Please enter the partition ID to activate ("0" for 1st, "1" for 2nd, ...).
echo.
echo Press [ENTER] to abort.
echo.
set /p PartitionNumber="Enter partition number: "
if "%PartitionNumber%" == "" goto EXIT
echo.
cls
echo Running: %MBRWIZFILE% /disk=%DriveNumber% /part=%PartitionNumber% /active /list
echo.
%MBRWIZFILE% /disk=%DriveNumber% /part=%PartitionNumber% /active /list
if "%errorlevel%" == "0" goto SUCCESS
echo.
goto EXIT

:InactivatePartition
title MBRWizard - De-activates the partition number
set DriveNumber=
set PartitionNumber=
echo.
echo Please enter the HDD to use ("0" for 1st, "1" for 2nd, ...)
echo.
echo Press [ENTER] to abort.
echo.
set /p DriveNumber="Enter drive number: "
if "%DriveNumber%" == "" goto EXIT
echo.
echo Please enter the partition ID to deactivate ("0" for 1st,
echo "1" for 2nd, ...; "*" for all).
echo.
echo Press [ENTER] to abort.
echo.
set /p PartitionNumber="Enter partition number: "
if "%PartitionNumber%" == "" goto EXIT
echo.
cls
echo Running: %MBRWIZFILE% /disk=%DriveNumber% /part=%PartitionNumber% /inactive /list
echo.
%MBRWIZFILE% /disk=%DriveNumber% /part=%PartitionNumber% /inactive /list
if "%errorlevel%" == "0" goto SUCCESS
echo.
goto EXIT

:DeletePartition
title MBRWizard - Deletes the partition
set DriveNumber=
set PartitionNumber=
echo.
echo Please enter the HDD to use ("0" for 1st, "1" for 2nd, ...)
echo.
echo Press [ENTER] to abort.
echo.
set /p DriveNumber="Enter drive number: "
if "%DriveNumber%" == "" goto EXIT
echo.
echo Please enter the partition ID to delete ("0" for 1st, "1" for 2nd, ...).
echo.
echo Press [ENTER] to abort.
echo.
set /p PartitionNumber="Enter partition number: "
if "%PartitionNumber%" == "" goto EXIT
echo.
cls
echo Running: %MBRWIZFILE% /disk=%DriveNumber% /part=%PartitionNumber% /del /list
echo.
%MBRWIZFILE% /disk=%DriveNumber% /part=%PartitionNumber% /del /list
goto EXIT

:WipeMBR
title MBRWizard - Wipes the MBR or wipes the first 63 sectors of disk
set DriveNumber=
set OPTION=
echo.
echo Please enter the HDD to use ("0" for 1st, "1" for 2nd, ...)
echo.
echo Press [ENTER] to abort.
echo.
set /p DriveNumber="Enter drive number: "
if "%DriveNumber%" == "" goto EXIT
echo.
echo Please enter "1" for wipes the MBR, "2" for wipes of first 63 sectors of disk.
echo.
echo Press [ENTER] to abort.
echo.
set /p OPTION="Enter option: "
if "%OPTION%" == "" goto EXIT
echo.
cls
echo Running: %MBRWIZFILE% /disk=%DriveNumber% /wipe=%OPTION% /list
echo.
%MBRWIZFILE% /disk=%DriveNumber% /wipe=%OPTION% /list
goto EXIT

:SaveMBR
title MBRWizard - Save the MBR to filename
set DriveNumber=
set Filename=
echo.
echo Please enter the HDD to use ("0" for 1st, "1" for 2nd, ...)
echo.
echo Press [ENTER] to abort.
echo.
set /p DriveNumber="Enter drive number: "
if "%DriveNumber%" == "" goto EXIT
echo.
echo Please enter filename to save (eg: hd0.mbr)
echo.
echo Press [ENTER] to abort.
echo.
set /p Filename="Enter filename: "
if "%Filename%" == "" goto EXIT
echo.
cls
echo Running: %MBRWIZFILE% /disk=%DriveNumber% /save=MBR /filename=%Filename%
echo.
%MBRWIZFILE% /disk=%DriveNumber% /save=MBR /filename=%Filename%
echo.
goto EXIT

:RestoreMBR
title MBRWizard - Reads and restores the Disk MBR from filename
set DriveNumber=
set Filename=
echo.
echo Please enter the HDD to use ("0" for 1st, "1" for 2nd, ...)
echo.
echo Press [ENTER] to abort.
echo.
set /p DriveNumber="Enter drive number: "
if "%DriveNumber%" == "" goto EXIT
echo.
echo Please enter filename to restore (eg: hd0.mbr)
echo.
echo Press [ENTER] to abort.
echo.
set /p Filename="Enter filename: "
if "%Filename%" == "" goto EXIT
echo.
cls
echo Running: %MBRWIZFILE% /disk=%DriveNumber% /restore=MBR /filename=%Filename% /list
echo.
%MBRWIZFILE% /disk=%DriveNumber% /restore=MBR /filename=%Filename% /list
echo.
goto EXIT

:ShowMBR
title MBRWizard - Shows contents of an existing MBR backup file
set Filename=
echo.
echo Please enter filename to display (eg: hd0.mbr)
echo.
echo Press [ENTER] to abort.
echo.
set /p Filename="Enter filename: "
if "%Filename%" == "" goto EXIT
echo.
cls
echo Running: %MBRWIZFILE%  /show=file /filename=%Filename%
echo.
%MBRWIZFILE% /show=file /filename=%Filename%
goto EXIT

:SortMBR
title MBRWizard - Sort MBR Entries by disk location
echo.
echo Running: %MBRWIZFILE% /issorted /list
echo.
%MBRWIZFILE% /issorted /list
if "%errorlevel%" == "1" goto NotSort
echo The partition entries in the MBR are already sorted.
goto EXIT

:NotSort
set INPUT=
echo The partition entries in the MBR are not sorted.
echo Do you want MBRWizard to sort the partition entries ?
echo.
echo Press [ENTER] to abort.
echo.
set /p INPUT="Enter [y]es or [n]o: "
echo.
if /I "%INPUT%" == "" goto EXIT
if /I "%INPUT%" == "n" goto EXIT
cls
echo Running: %MBRWIZFILE% /sort /list
echo.
%MBRWIZFILE% /sort /list
if "%errorlevel%" == "0" goto SUCCESS
goto EXIT

:SUCCESS
echo.
echo Operation completed successfully.
echo.
goto EXIT

:EXIT
set _exit=
echo.
echo Do you want to exit MBRWiz ?
echo.
set /p _exit="Enter [y]es or [n]o: "
if /I "%_exit%" == "" goto EXIT
if /I "%_exit%" == "n" goto MENU
if /I "%_exit%" == "y" goto END


:BOOTMENU
cls
echo Running: %MBRWIZFILE% /bootmenu
echo.
%MBRWIZFILE% /bootmenu
echo.
if "%errorlevel%" == "0" goto SUCCESS
echo.
goto EXIT

:_ERROR1
echo.
echo ERROR: %MBRWIZFILE% file not found
echo Kindly check if you have downloaded the MBRWiz from
echo http://www.mbrwizard.com
goto END

:END
endlocal

REM ------------- END 1mbrwiz.cmd codes --------------------------